te******@gmail.com wrote:
Guys,
I need to know what kind of characters is being used in a textbox,
whether Latin or Unicode. Depending on that I want to make a countdown.
For example:
if the characters are Latin, i want the countdown to start with 200
if it contained a unicode character, then it will start with 100.
Any ideas?
What do you mean by "unicode characters"? All Latin-alphabet characters
are also part of Unicode. Furthermore, "Latin" might mean different
things to different people.
If you want to scan the string for any characters outside the normal
ASCII range, you can just loop through and test the code of each
character:
function containsNonASCII(s) {
for (var pos in s) {
var c = s.charCodeAt(pos)
if (c < 0x20 || c > 0x7f) return true;
}
return false;
}
Note that this will exclude accented characters as well. If you want to
count those as Latin, you'll need to modify the function to allow
whichever specific subranges -- that's left as an exercise to the
reader.
-- David