zip and tel function

E

Eugene Anthony

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
 
R

Ray Costanzo [MVP]

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
 
E

Eugene Anthony

The problem would be very much on dealing with international phone
numbers and zip codes.

Regards

Eugene Anthony
 
E

Eugene Anthony

I found a simple solution:

function isInt(input)

Set re = new RegExp
re.Pattern = "^\d+$"
re.Global = true
isInt = re.test(input)

end function


Regards

Eugene Anthony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top