views:

98

answers:

3

How to validate a numeric numbers?

A: 
var number_string = document.getElementById("my_input").value;
is_valid = /^[0-9]+$/.test(number_string);

Don't forget to server-side validate as well!

MiffTheFox
Just for the record, if you want to allow commas or dollar signs just add them after the 9 in the brackets.
Michael Shnitzer
A: 

There's also a pretty nice implementation of isNumeric here.

R0MANARMY