Validate Numeric Fields Using Javascript.
By Nannette Thacker - 1/18/2001

Use the onBlur() method to validate numeric fields with this checkNumeric() javascript function. Optionally pass in a period, comma, or hypen to indicate allowed values. Set the maximum and minimum value allowed.

Allow Comma, Period, Negative
No Comma, Period, Negative
If your allowed values always include period, comma, or hyphen, or never include those, you may easily edit the function to remove the parameter values from the onBlur() and function.

You may also use a variation of this routine to check for any combination of valid values. You don't have to use "0123456789" - you may instead use something else as your check string.

Here is the javascript:

  

Here is the HTML:

 
Allow Comma, Period, Negative
No Comma, Period, Negative