Is A letter?

# Thread: Is A letter?

1. Senior Member
Join Date
Dec 1969
Posts
701

## Is A letter?

Is there a funcion that finds out if a character is a letter much like the isNumeric function?

2. Senior Member
Join Date
Dec 1969
Posts
2,493

## RE: Is A letter?

If Not IsNumeric("123A45") :-)

3. Junior Member
Join Date
Dec 1969
Posts
4

## RE: Is A letter?

that&#039;ll include \$#!@\$@#\$ .,/][{} etc<BR><BR>use asc (string) and check the number to see if it is in the range of lower and upper case letters<BR><BR>http://www.w3schools.com/vbscript/func_asc.asp

4. Senior Member
Join Date
Dec 1969
Posts
10,852

## Or better yet...

Just use a RegEx to do it. Set the pattern to something like [a-zA-Z]+ and be done with it.<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## But he asked...

...to check a *SINGLE* character, as to whether or not it is a letter.<BR><BR>Your + there will check for any number of alphabetic characters.<BR><BR>And if you are using that to test a *string* of characters for alphabetic only, it fails in the same way as the NOT ISNUMERIC does.<BR><BR>That is, if I have the string "12X\$!", testing it against the regexp [a-zA-Z]+ *will* see the "X" in that and say "Oh! A match. So it&#039;s okay."<BR><BR>For this kind of testing, you want a *MISMATCH* test:<BR><BR>[^a-zA-Z]<BR><BR>The ^ character there says "NOT any of the following characters."<BR><BR>So if you test a string and find a match on *that* expression, then you know it contains something *other* than all alphabetic characters. Presto. A mismatch.<BR><BR>The mismatch test is a lot easier than a match test, where you&#039;d have to insist on having the same number of matches as you have characters.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## Despite all the complexity...

...of the other answers, including my own, if you really want to test a *single* character, then do it the easy way:<BR><BR>&#060;%<BR>character = "?" &#039; one character, any kind<BR>If LCase("character") &#062;= "a" AND LCase("character") &#060;= "z" Then<BR> &#039; yes, it&#039;s a letter<BR>Else<BR> &#039; no, it is not<BR>End If<BR>%&#062;<BR><BR>If you need this as a function:<BR><BR>&#060;%<BR>Function IsALetter( ch )<BR> If Len(ch) &#062; 1 Then<BR> Response.Write "IsALetter called with more than one character: " & ch<BR> Response.End<BR> End If<BR> IsALetter = (LCase("character") &#062;= "a" AND LCase("character") &#060;= "z")<BR>End Function<BR>%&#062;<BR><BR>Why work harder than that?<BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
355

## Minor correction

"character" taken out of quotes and<BR>"character" =&#062; ch<BR><BR><BR>&#060;%<BR>character = "?" &#039; one character, any kind<BR>If LCase(character) &#062;= "a" AND LCase(character) &#060;= "z" Then<BR>&#039; yes, it&#039;s a letter<BR>Else<BR>&#039; no, it is not<BR>End If<BR>%&#062;<BR><BR>If you need this as a function:<BR><BR>&#060;%<BR>Function IsALetter( ch )<BR>If Len(ch) &#062; 1 Then<BR>Response.Write "IsALetter called with more than one character: " & ch<BR>Response.End<BR>End If<BR>IsALetter = (LCase(ch) &#062;= "a" AND LCase(ch) &#060;= "z")<BR>End Function<BR>%&#062;

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## Thanks!

Too much copy/paste. Sigh.<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
484

## all very precise

you are... (Yoda)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•