2

How to validate a numeric numbers?

ire_and_curses
  • 66,119
  • 22
  • 112
  • 139
rythmvasu
  • 21
  • 1

2 Answers2

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
  • 20,803
  • 14
  • 67
  • 92
1

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

Community
  • 1
  • 1
Roman
  • 18,451
  • 5
  • 62
  • 83