2

How to validate a numeric numbers?

2
  • Look here - this has the answer stackoverflow.com/questions/1303646/… Commented Apr 18, 2010 at 2:54
  • 1
    do you mean the datatype is number or string type number? var strNum = '123'; Commented Apr 18, 2010 at 4:33

2 Answers 2

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!

Sign up to request clarification or add additional context in comments.

1 Comment

Just for the record, if you want to allow commas or dollar signs just add them after the 9 in the brackets.
1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.