Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How I can check(validate) if this var is an integer and appear appropriate message

    ASP/VBSCRIPT
    When I fill a field in an html form , and this want to be an integer ... well when I get this with POST to an asp document, How I can check(validate) if this is an integer and appear appropriate message if it is not ?

    entry=6778 or "78yut" or "khgdds"
    <%
    ...
    string = request.form("entry")
    int = Cint(string)
    If (not(isNumeric(int))) then
    response.write "Please enter a number"
    response.end
    end if
    ...
    %>

    if entry="string" may avoid error [I will have error here ?] in
    int = Cint(string)
    ?

  • #2
    Regular Coder
    Join Date
    Jan 2005
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts
    check for isNumeric to see if it's a number
    Code:
    strEntry = request.form("entry")
    if Not isNumeric(strEntry) Then
         response.Write("Please enter a number")
    else
         --whatever you do if it's a number
    end if

  • #3
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,062
    Thanks
    4
    Thanked 8 Times in 8 Posts
    string = request.form("entry")
    int = Cint(string)


    The reason that will throw an error is because you didn't checked to make sure if it was a numeric value until after you tried to convert the incoming form field to the integer.

    the function cint is used to convert a number to an integer.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •