How to validate a numeric numbers?
Asked
Active
Viewed 797 times
2
-
1do you mean the datatype is number or string type number? var strNum = '123'; – Sungguk Lim Apr 18 '10 at 04:33
-
Look here - this has the answer http://stackoverflow.com/questions/1303646/check-variable-whether-is-number-or-string-in-javascript – Romain Hippeau Apr 18 '10 at 02:54
2 Answers
1
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
- 21,302
- 14
- 69
- 94
-
Just for the record, if you want to allow commas or dollar signs just add them after the 9 in the brackets. – Michael Shnitzer Apr 18 '10 at 02:54