compare alphanumeric number with integer problem

Discussion in 'Javascript' started by Matt, Sep 11, 2004.

  1. Matt

    Matt Guest

    I want to compare the address number in javascript, and the address
    number
    is alphanumeric. I have a text box and the user needs to enter the
    number between 2 numbers as follows (e.g. Please enter the address
    number between N11800 and N12800). Note that N11800 and N12800 are
    dynamic, it can be pure integers. But this is just an example.

    The bug is if the user enter a number that is an integer, for example,
    111,
    then it still consider as good number. But if I entered A333, then it
    has error.

    I know I can comment out the following, so that just pure string
    comparison. But it sometimes doesn't work.

    //if (!isNaN(strValue) && strValue != '')
    // strValue = parseInt(strValue);

    I guess the wrong I really have no idea what's going on.

    Please help. Thanks!!

    <html>
    <head>
    <script type="text/javascript">
    function checkField()
    {
    var startNumber = "N11800";
    var endNumber = "N12800";
    var strValue = document.InputForm.txtNumber.value;
    alert("You entered = " + strValue);
    if (!isNaN(strValue) && strValue != '')
    strValue = parseInt(strValue);

    //just pure string comparisons
    if ( strValue == '' || (strValue < startNumber || strValue >
    endNumber)){
    alert("Please enter a number between " + startNumber + " and " +
    endNumber);
    InputForm.txtNumber.value = "";
    InputForm.txtNumber.focus();
    return false;
    }
    else
    { alert("good number");
    return true;
    }
    }
    </script>
    </head>
    <body>
    <FORM NAME="InputForm">
    <P>Please enter the address number between N11800 and N12800:
    <input type="text" name="txtNumber">
    <P><input type="button" value="check field" onClick="checkField()">
    </form>
    </body>
    </html>
    Matt, Sep 11, 2004
    #1
    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. VB Programmer

    Check if var is alphanumeric?

    VB Programmer, Nov 16, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    577
    bruce barker
    Nov 16, 2004
  2. Steven J Sobol
    Replies:
    8
    Views:
    5,668
    Thomas Weidenfeller
    Apr 30, 2004
  3. Paul
    Replies:
    1
    Views:
    13,188
    Rogan Dawes
    Sep 14, 2004
  4. fooboo
    Replies:
    9
    Views:
    608
    Eric Sosman
    Jun 7, 2005
  5. Matt

    compare alphanumeric problem

    Matt, Sep 14, 2004, in forum: Javascript
    Replies:
    4
    Views:
    345
    Dr John Stockton
    Sep 19, 2004
Loading...

Share This Page