469,287 Members | 2,637 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,287 developers. It's quick & easy.

Grab the text from a textbox

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?

Oct 26 '05 #1
2 1245
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

Oct 26 '05 #2
David Wahler wrote:
function containsNonASCII(s) {
for (var pos in s) {
Won't work with a strict ECMAScript implementation and not with MS JScript
(at least not with all versions) since String objects do not have numbered
properties for each character of the string value there.

for (var pos = s.length; pos--;)
{

will always work.
var c = s.charCodeAt(pos)
if (c < 0x20 || c > 0x7f) return true;
}
return false;
}


/[^\x20-\x7F]/.test(s)

will work in JavaScript from version 1.3 (NN4), ECMAScript version < 3
and compatibles but will maybe exclude Unicode characters.

/[^\u0020-\u007F]/.test(s)

will work in ECMAScript 3+ and compatibles and should include all Unicode
characters.

BTW, the range [\x00-\x1A] does contain ASCII characters with, just not
printable ones, i.e. the function identifier does not reflect its purpose.
PointedEars
Oct 26 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by dan glenn | last post: by
reply views Thread by Baby Blue | last post: by
8 posts views Thread by Dennis C. Drumm | last post: by
4 posts views Thread by louise raisbeck | last post: by
6 posts views Thread by Lance Geeck | last post: by
4 posts views Thread by Eric Layman | last post: by
16 posts views Thread by mj.redfox.mj | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.