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

    *** Sent via Developersdex http://www.developersdex.com ***
    Eugene Anthony, Jul 12, 2005
    #1
    1. Advertising

  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
    "Eugene Anthony" <> wrote in message
    news:...
    > 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 ***
    Ray Costanzo [MVP], Jul 12, 2005
    #2
    1. Advertising

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

    Regards

    Eugene Anthony

    *** Sent via Developersdex http://www.developersdex.com ***
    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

    *** Sent via Developersdex http://www.developersdex.com ***
    Eugene Anthony, Jul 13, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sunil_varma
    Replies:
    1
    Views:
    1,129
  2. Link
    Replies:
    1
    Views:
    318
    Abecedarian
    May 7, 2005
  3. Link
    Replies:
    3
    Views:
    398
    Rolf Magnus
    May 7, 2005
  4. Link
    Replies:
    0
    Views:
    283
  5. aki
    Replies:
    2
    Views:
    273
    Chris Thomasson
    Jul 22, 2008
Loading...

Share This Page