I need to know how to determine unicode input either Utf8/Utf16 (non-latin) or latin on text area type of html and its validation with javascript. I googled but could not find what i looked for.
Asked
Active
Viewed 522 times
1
-
So you want to know if a user has entered unicode into a textarea? – Alex W Jan 16 '13 at 04:57
-
1What do you mean "unicode input"? It is really hard to get non-Unicode text in JavaScript... Also some sample code probably would make question more clear. – Alexei Levenkov Jan 16 '13 at 04:58
-
@AlexW: currently i am required to distinguish either text only input or unicode input on text area type of html since the entry must relate to both kind of inputs. Any suggestion? – Doni Andri Cahyono Jan 16 '13 at 05:27
-
@AlexeiLevenkov: Unicode classified by Utf8 and Utf16 type. I tried to google and found this http://www.webtoolkit.info/javascript-utf8.html but still couldn't figure out how to determine the input from user to make a validation. – Doni Andri Cahyono Jan 16 '13 at 05:31
-
1All text is Unicode. Perhaps you mean "non-ANSI" characters, those with code points above 255? You could check the codepoint using the string.charCodeAt(n) function. – Jan 16 '13 at 05:35
-
You could check if a regular expression for unicode range characters matches: http://stackoverflow.com/questions/7114185/javascript-validate-user-input-against-desired-character-set-encoding – Alex W Jan 16 '13 at 05:37
-
@torazaburo: Perhaps, latin and non-latin are more exact. – Doni Andri Cahyono Jan 16 '13 at 05:39
-
@AlexW: For sure, will it work to determine latin and non-latin? – Doni Andri Cahyono Jan 16 '13 at 05:49
-
@DoniAndriCahyono If you know the escape character ranges for Latin and Non-Latin characters. – Alex W Jan 16 '13 at 05:50
-
JavaScript strings are [more-or-less Utf16](http://stackoverflow.com/questions/8715980/javascript-strings-utf-16-vs-ucs-2). Most likly link provided by AlexW should solve your problem, otherwise - consider checking `string.charCodeAt(n)` against list of charactes you accept. – Alexei Levenkov Jan 16 '13 at 05:52
-
@AlexeiLevenkov: Could you please give snippet examples? – Doni Andri Cahyono Jan 16 '13 at 08:38
-
@AlexW: Is http://en.wikipedia.org/wiki/Latin_script_in_Unicode enough? CMIIW – Doni Andri Cahyono Jan 16 '13 at 08:39
-
This not a duplicate. Instead, it is not a real question – there is no description of what the code should really *do*, and no existing code (not even HTML, still less a JavaScript attempt) has been posted. – Jukka K. Korpela Jan 16 '13 at 09:44
-
This is a real question, in-fact we are so much into unicode we don't that we need to know charset of user input. – EGL 2-101 Jul 10 '15 at 09:28