2

How to validate a numeric numbers?

ire_and_curses
  • 68,372
  • 23
  • 116
  • 141
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
  • 21,302
  • 14
  • 69
  • 94
1

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

Community
  • 1
  • 1
Roman
  • 19,581
  • 6
  • 68
  • 84