flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicholas Kwiatkowski <nicho...@spoon.as>
Subject Re: What's the easiest way to tell if a character is a letter or not?
Date Mon, 22 Apr 2013 02:12:01 GMT
You would probably want to use the charCodeAt() function on the string.
 Assuming you want to search for printable, latin characters, the codes
would be 65 - 90 (upper case A-Z) and 97 - 122 (lower case a-z).

if ((letter.charCodeAt(0) >= 65) && (letter.charCodeAt(0) <= 90)) ||
((letter.charCodeAt(0) >= 97) && (letter.charCodeAt(0) <= 122))
  {
     stuff
  }

If you don't care if you catch the printable characters of [\]^_`  you
could just use the range of 65 -> 122.  A full ASCII code table is at
http://ascii-table.com/ascii.php    (or if you have an MS-DOS book
available)

-Nick


On Sun, Apr 21, 2013 at 9:05 PM, Justin Mclean <justin@classsoftware.com>wrote:

> Hi,
>
> Anyone know how to work out if a character, including unicode characters,
> is a letter or not?
>
> This is not the right way of doing it:
>
>             if ("a" <= letter && letter <= "z" ||
>                 "A" <= letter && letter <= "Z")
>
> From the DateFormatter class for the curious.
>
> Thanks,
> Justin
>
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message