rythmvasu
rythmvasu

Reputation: 21

How do I validate numbers in Javascript?

How to validate a numeric numbers?

Upvotes: 2

Views: 824

Answers (2)

Roman
Roman

Reputation: 20246

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

Upvotes: 1

MiffTheFox
MiffTheFox

Reputation: 21555

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

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

Upvotes: 1

Related Questions