• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to detect the input from user is ENLGISH ONLY

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

How to detect the input from user is ENLGISH ONLY (include common symbol) in the <input name="message" type="text"> ?

Since I want to ensure the string input by the user is english. If they input other mulitbyte string, e.g. Chinese character. I will alert them to input English.

Thanks
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
basically I believe you are going to have to look at what the character code is for each key press.

Eric
 
Vince Hon
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this one work.

function checkIsEnglishString(MESSAGE){

ESCAPE_MESSAGE = escape(MESSAGE);
var msgLang = ""
var isEng = true;

for (i=0;i<ESCAPE_MESSAGE.length;i++) {
if (ESCAPE_MESSAGE.charAt(i)=="%") {
//check if it is chinese. %uXXXX represent unicode character.
if (ESCAPE_MESSAGE.charAt(i+1)=="u" || ESCAPE_MESSAGE.charAt(i+1)=="A" || ESCAPE_MESSAGE.charAt(i+1)=="B" || ESCAPE_MESSAGE.charAt(i+1)=="C" || ESCAPE_MESSAGE.charAt(i+1)=="D" || ESCAPE_MESSAGE.charAt(i+1)=="E" || ESCAPE_MESSAGE.charAt(i+1)=="F") {

msgLang="chin"; isEng = false;
break;
//if it is not the %uXXXX or %uXX format, it is English
}else{
msgLang="english";
}
}
}

return isEng;
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic