I am using the TextInput Flex 4.5 component to input some English text. I use the restrict attribute to ... restrict keyboard input to a-zA-Z characters only. The problem is that if I copy / paste a word into another language, I can paste it into the TextInput component. Is there any way to avoid this? If not, how can I check the input in the specified language?
I found out that the Unicode character set with Chinese + languages is \ u4E00 to \ u9FFF. Therefore, I write the following:
var chRE:RegExp = new RegExp("[\u4E00-\u9FFF]", "g");
if (inputTI.text.match(chRE)) {
trace("chinese");
}
else {
trace("other");
}
But if I enter the word "hello" in TextInput, then it checks ... What is the error?
Since I cannot (my mistake? Or mistake?), Use the Unicode range with RegExp, I wrote the following function to check if there is a word in Chinese and what it is.
private function isChinese(word:String):Boolean
{
var wlength:int = word.length;
for (var i:int = 0; i < wlength; i++) {
var charCode:Number = word.charCodeAt(i);
if (charCode <= 0x4E00 || charCode >= 0x9FFF) {
return false;
}
}
return true;
}
source
share