isNumeric()

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

  1. I have received the following feedback for the two functions bellow:

    "The ISNUMERIC test is WORTHLESS for checking for an INT value, because
    ISNUMERIC will happily accept DOUBLE values, such as 89.11998811777 and
    other values that are simply *NOT* INT values."


    <%
    function isZip(input)

    isZip = false

    if len(input) = 5 then

    isZip = (isNumeric(input))

    end if

    if len(input) = 10 then

    z1 = left(input,5)
    z2 = right(input,4)
    z3 = mid(input,6,1)

    isZip = (isNumeric(z1) and isNumeric(z2) and z3="-")

    end if

    end function

    function isPhone(input)

    Dim tempPh

    tempPh = replace(input," ","")
    tempPh = replace(input,"-","")
    tempPh = replace(input,"-","")
    tempPh = replace(input,"(","")
    tempPh = replace(input,")","")

    isPhone = (isNumeric(tempPh))

    end function

    %>


    How do I solve the problem?.

    Your help is kindly appreciated.

    Regards

    Eugene Anthony

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

  2. If all you want to do is test whether it's an integer:

    function isInt(pData)
    on error resume next
    dim test
    test=clng(pData)
    if err<>0 then
    isInt=false
    else
    if pData <> test then
    isInt=false
    else
    isInt=true
    end if
    end if
    on error goto 0
    end function

    Eugene Anthony wrote:
    > I have received the following feedback for the two functions bellow:
    >
    > "The ISNUMERIC test is WORTHLESS for checking for an INT value,
    > because ISNUMERIC will happily accept DOUBLE values, such as
    > 89.11998811777 and other values that are simply *NOT* INT values."
    >
    >
    > <%
    > function isZip(input)
    >
    > isZip = false
    >
    > if len(input) = 5 then
    >
    > isZip = (isNumeric(input))
    >
    > end if
    >
    > if len(input) = 10 then
    >
    > z1 = left(input,5)
    > z2 = right(input,4)
    > z3 = mid(input,6,1)
    >
    > isZip = (isNumeric(z1) and isNumeric(z2) and z3="-")
    >
    > end if
    >
    > end function
    >
    > function isPhone(input)
    >
    > Dim tempPh
    >
    > tempPh = replace(input," ","")
    > tempPh = replace(input,"-","")
    > tempPh = replace(input,"-","")
    > tempPh = replace(input,"(","")
    > tempPh = replace(input,")","")
    >
    > isPhone = (isNumeric(tempPh))
    >
    > end function
    >
    > %>
    >
    >
    > How do I solve the problem?.
    >
    > Your help is kindly appreciated.
    >
    > Regards
    >
    > Eugene Anthony
    >
    > *** Sent via Developersdex http://www.developersdex.com ***


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Jul 11, 2005
    #2
    1. Advertising

  3. When I did this I am getting an invalid phone and zip code.


    function isInt(input)

    on error resume next

    Dim Tem
    Tem = Clng(input)

    if err <> 0 then

    isInt = false

    else

    if(Tem <> input) then
    isInt = false
    else
    isInt = true
    end if

    end if

    on error goto 0

    end function

    function isZip(input)

    isZip = false

    if len(input) = 5 then

    isZip = (isInt(input))

    end if

    if len(input) = 10 then

    z1 = left(input,5)
    z2 = right(input,4)
    z3 = mid(input,6,1)

    isZip = (isInt(z1) and isInt(z2) and z3="-")

    end if

    end function

    function isPhone(input)

    Dim tempPh

    tempPh = replace(input," ","")
    tempPh = replace(input,"-","")
    tempPh = replace(input,"-","")
    tempPh = replace(input,"(","")
    tempPh = replace(input,")","")

    isPhone = (isInt(tempPh))

    end function


    Regards

    Eugene Anthony

    *** Sent via Developersdex http://www.developersdex.com ***
     
    Eugene Anthony, Jul 11, 2005
    #3
  4. Eugene Anthony

    Roland Hall Guest

    "Eugene Anthony" wrote in message
    news:O0R4u%...
    : When I did this I am getting an invalid phone and zip code.
    :
    :
    : function isInt(input)
    :
    : on error resume next
    :
    : Dim Tem
    : Tem = Clng(input)
    :
    : if err <> 0 then
    :
    : isInt = false
    :
    : else
    :
    : if(Tem <> input) then
    : isInt = false
    : else
    : isInt = true
    : end if
    :
    : end if
    :
    : on error goto 0
    :
    : end function
    :
    : function isZip(input)
    :
    : isZip = false
    :
    : if len(input) = 5 then
    :
    : isZip = (isInt(input))
    :
    : end if
    :
    : if len(input) = 10 then
    :
    : z1 = left(input,5)
    : z2 = right(input,4)
    : z3 = mid(input,6,1)
    :
    : isZip = (isInt(z1) and isInt(z2) and z3="-")
    :
    : end if
    :
    : end function
    :
    : function isPhone(input)
    :
    : Dim tempPh
    :
    : tempPh = replace(input," ","")
    : tempPh = replace(input,"-","")
    : tempPh = replace(input,"-","")
    : tempPh = replace(input,"(","")
    : tempPh = replace(input,")","")
    :
    : isPhone = (isInt(tempPh))
    :
    : end function

    It's probably easier using a regular expression and just have the user enter
    just digits.

    Ex.

    <%@ Language=VBScript %>
    <%
    Option Explicit
    Response.Buffer = True

    function checkPhone(strInput)
    dim re, matches, match
    set re = new RegExp
    re.Pattern = "\d{10}" ' phone 10 digits decimal only
    set match = re.Execute(strInput)
    if match.count > 0 then
    checkPhone = true
    else
    checkPhone = false
    end if
    set match = nothing
    set re = nothing
    end function

    Response.Write "9009766969: " & checkPhone("9009766969") & "<br />" & vbCrLf
    Response.Write "800XYZ1234: " & checkPhone("800XYZ1234") & "<br />" & vbCrLf
    %>

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Jul 11, 2005
    #4
  5. Roland Hall wrote:
    >
    > It's probably easier using a regular expression and just have the
    > user enter just digits.
    >
    > Ex.
    >
    > <%@ Language=VBScript %>
    > <%
    > Option Explicit
    > Response.Buffer = True
    >
    > function checkPhone(strInput)
    > dim re, matches, match
    > set re = new RegExp
    > re.Pattern = "\d{10}" ' phone 10 digits decimal only
    > set match = re.Execute(strInput)
    > if match.count > 0 then
    > checkPhone = true
    > else
    > checkPhone = false
    > end if
    > set match = nothing
    > set re = nothing
    > end function
    >
    > Response.Write "9009766969: " & checkPhone("9009766969") & "<br />" &
    > vbCrLf Response.Write "800XYZ1234: " & checkPhone("800XYZ1234") &
    > "<br />" & vbCrLf %>
    >


    And, from http://regexlib.com/REDetails.aspx?regexp_id=924 here's the zip
    code pattern:

    re.Pattern = "^\d{5}((-|\s)?\d{4})?$"Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Jul 11, 2005
    #5
    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. Stephan Bour

    IsNumeric C# equivalent

    Stephan Bour, Nov 5, 2003, in forum: ASP .Net
    Replies:
    12
    Views:
    243,968
    daniefvh
    Jan 26, 2012
  2. martin
    Replies:
    3
    Views:
    10,621
    Kevin Spencer
    Jul 19, 2004
  3. =?Utf-8?B?TXJNaWtl?=

    IsNumeric Function

    =?Utf-8?B?TXJNaWtl?=, Nov 29, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    4,864
    Dan Bass
    Nov 29, 2004
  4. David Lozzi

    Name 'IsNumeric' is not declared???

    David Lozzi, Dec 6, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    4,449
    David Lozzi
    Dec 7, 2004
  5. Steve Kershaw

    Is there any IsNumeric in C#?

    Steve Kershaw, Nov 3, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    78,560
    Bill.Kanzaki
    Feb 3, 2012
Loading...

Share This Page