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. Advertisements

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. Noozer
    Replies:
    2
    Views:
    4,328
    Noozer
    Sep 19, 2004
  2. =?Utf-8?B?Sm9ubyBKb25lcw==?=

    Int64 outside range of the Integer setting on Compare Validator

    =?Utf-8?B?Sm9ubyBKb25lcw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    618
    =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=
    May 9, 2006
  3. FC
    Replies:
    3
    Views:
    504
    Ioannis Vranos
    Mar 4, 2005
  4. w00
    Replies:
    5
    Views:
    1,581
  5. fooboo
    Replies:
    9
    Views:
    733
    Eric Sosman
    Jun 7, 2005
  6. Hellmut Weber
    Replies:
    8
    Views:
    4,544
  7. Matt

    compare alphanumeric problem

    Matt, Sep 14, 2004, in forum: Javascript
    Replies:
    4
    Views:
    457
    Dr John Stockton
    Sep 19, 2004
  8. Roedy Green

    Oops! Integer.compare

    Roedy Green, May 25, 2012, in forum: Java
    Replies:
    2
    Views:
    290
    Owen Jacobson
    May 30, 2012
Loading...