zip and tel function

Discussion in 'ASP General' started by Eugene Anthony, Jul 12, 2005.

  1. 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
     
    Eugene Anthony, Jul 12, 2005
    #1
    1. Advertisements

  2. 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
     
    Ray Costanzo [MVP], Jul 12, 2005
    #2
    1. Advertisements

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

    Regards

    Eugene Anthony
     
    Eugene Anthony, Jul 12, 2005
    #3
  4. 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
     
    Eugene Anthony, Jul 13, 2005
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.