isInt could be a bit refined.
Function isInt(sInput)
isInt = False
If Not isReallyNumeric(sInput) Then Exit Function
isInt = CLng(sInput) = CDbl(sInput)
End Function
'Your phone number regular expression is kinda odd, I think. Do phone
numbers start with spaces and then a "-" character?
'The way I've done phone numbers before, so as not to force people into
following the correct (xxx) xxx-xxxx US format is something like this. You
could get a bit more involved, like validating that a phone number doesn't
start with a 0 or something, or doesn't require area codes, etc.
Function isPhone(sInput)
isPhone = False
Dim s: s = sInput
''RE would probably be better here...
s = Replace(Replace(Replace(Replace(s, "(", ""), ")", ""), "-", ""), "
", "")
If isReallyNumeric(s) And Len(s) = 10 Then isPhone = True
End Function
'You could do the same thing with the zip
Function isZIP(sInput)
isZIP = False
Dim s: s = sInput
s = Replace(s, "-", "")
If Not isReallyNumeric(s) Then Exit Function
If Len(s) = 5 Or Len(s) = 9 Then isZIP = True
End Function
Function isReallyNumeric(str)
'
http://www.aspfaq.com/show.asp?id=2390
isReallyNumeric = True
For i = 1 To Len(str)
D = Mid(str, i, 1)
If Asc(D) < 48 Or Asc(D) > 57 Then
isReallyNumeric = False
Exit For
End If
Next
End Function
Ray at work
End Function
"Eugene Anthony" <so***********@yahoo.com> wrote in message
news:OD*************@TK2MSFTNGP14.phx.gbl...
Bellow are two functions that I use to validate my zipcode and telephone
number:
function isInt(input)
on error resume next
Dim Temp
Temp = Clng(input)
isInt = (err=0 and inStr(input,".") = 0)
on error goto 0
end function
function isPhone(input)
Set re = new RegExp
re.Pattern = "[\s\-\(\)\+]"
re.Global = true
isPhone = (isInt(re.replace(input,"")))
end function
function isZip(input)
Set re = new RegExp
re.Pattern = "[\s\-]"
re.Global = true
isZip = (isInt(re.replace(input,"")))
end function
Are these functions considered to be feasible for validation?.
Your help is kindly appreciated.
Regards
Eugene Anthony
*** Sent via Developersdex http://www.developersdex.com ***