pls help me with "IsNaN function"

javascript United States
  • 19 years ago

    hie! i'm having some trouble using the IsNaN function...i hope to validate the age to determine whether it is numeric or not before submitting the form.....
    i want the function to return false when it is not a number ...but function isNaN returns true when it is not a number.....
    any other function i can use???


    pls help...below is my codes..it is not working....


    thanks in advance



    <SCRIPT>  
    function Validator(theForm)
    if (IsNaN(frmCusInfo.txtAge.value))
      {  
       alert("Please enter a numeric number for the \"Age\" field.");
       frmCusInfo.txtAge.focus();
    //  return (false);    i want this function to return false
    }    
    </SCRIPT>


    <FORM name=frmCusInfo  onsubmit="return Validator(this)" method=post>


    ...


    <INPUT name=txtAge type=text style="HEIGHT: 22px; WIDTH: 26px">



    ....


    </FORM>


  • 19 years ago

    First thing, whenever you pull a field value in JavaScript it always returns a string.
    This, frmCusInfo.txtAge.value, will always return a string.


    Try using Regular Expressions or look below at my example.


    Let's look at my example below where I only allow dollar amounts and formatting.  You can modify to fit your needs.


    <!-- Function Description:  Validates Non Currencys fields. -->


    function validateDollar( fld )
    {
       var temp_value = fld.value;


       if (tempvalue == "")
       {
         fld.value = "$0.00";
         return;
       }
       var Chars = "0123456789.,$";
       for (var i = 0; i < temp
    value.length; i++)
       {
           if (Chars.indexOf(temp_value.charAt(i)) == -1)
           {
               alert("Invalid Character(s)\n\nOnly numbers (0-9), a dollar sign, a comma, and a period are allowed in this field.");
               fld.focus();
               fld.select();
               return;
           }
       }
    }

  • 18 years ago

    string = document.form.text.value;
    number = parseInt(string);
    document.write(number);


    that sorta think should help ya

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Some people, when confronted with a problem, think "I know, I’ll use regular expressions." Now they have two problems.” - Jamie Zawinski