Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Check, Numbers and Letters Only.

1. ## Check, Numbers and Letters Only.

I am going very slow at the moment, and I can not remember how to check a string to make sure it's only numbers and letters as characters and not other symbols.

Thank you.

• I found it out...

This will be my function...
Code:
```Dim Z As String, X As Integer

For I = 1 To Len(Z)

X = Asc(Mid(Z, I, 1))

If Not ((X >= 48 And X <= 57) Or (X >= 65 And X <= 90) Or (X >= 97 And X <= 122)) Then

MsgBox "error"

End If

Next```

• Originally posted by oracleguy
http://www.codingforums.com/showthre...&threadid=7472

Like this?
Well, I didn't see your post there until now, but thanks for the support!

• I have a more concise function now - perhaps may be improved upon in the future, but as simple as I know how - however I do like your approach of using Asc() values, Morgoth, that's yet another way to do it! It's probably not as fast though since you're looping.

Code:
```Function IsAlphaNumeric(str)
Dim ianRegEx
Set ianRegEx = New RegExp
ianRegEx.Pattern = "[^a-zA-Z0-9]"
ianRegEx.Global = True
IsAlphaNumeric = (ianRegEx.Test(str) = False)
End Function```
http://www.solidscripts.com/displayscript.asp?sid=10

Example usage:

Code:
```<%
If IsAlphaNumeric("SDF(**(&") = False Then
Response.Write("Please refrain from using characters other than letters or numbers in your entry.")
End If
%>```

• Thank you whammy.

I haven't really gotten into RegExp. I don't really understand exactly what it is.

Do you hav any tutorials?
I used two scripts, now three, that use this, and I want to understand what it is doing, how, and why.

Thanks again.

• Some great tutorials here:

What this does:
Code:
```Function IsAlphaNumeric(str)
Dim ianRegEx
Set ianRegEx = New RegExp
ianRegEx.Pattern = "[^a-zA-Z0-9]"
ianRegEx.Global = True
IsAlphaNumeric = (ianRegEx.Test(str) = False)
End Function```
[^a-zA-Z0-9]
• [] - character grouping brackets
• ^ - when inside grouping brackets, means "NOT" (otherwise it represents the beginning of the string)
• a-zA-Z0-9 - the characters NOT to match

the reason I use

IsAlphaNumeric = (ianRegEx.Test(str) = False)

is because if you use:

[a-zA-Z0-9] (notice there is no NOT)

then

IsAlphaNumeric = ianRegEx.Test(str)

will ALWAYS return true if ANY of those characters exist...

• Thank you whammy.

• ## lazy way

an easy or lazy way is

dim _myInt as integer

public property isInteger() as boolean

get

dim _i as integer
try
_i = cInt(_myInt)
return true
catch
return false
end try
and get
set

_myInt = value
and set

end property

if true then it is an integer , if not ... not

• And how does that account for Alpha characters?

• ## string

yes for string you just use regular Expression but for any other format (date ect.. ) you cabn use that leasy way

or even easier

Dim MyVar As Object
Dim MyCheck As Boolean

MyVar = "53" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "459.95" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "45 Help" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns False

•

#### Posting Permissions

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