Vg. Vg. - 2 years ago 159
Javascript Question

Regex for age validation that accepts an age between 0-200 using Javascript only

I want a regex that allows users to enter only numbers between 0 and 200.
I've tried this but it doesn't work:

var age_regex=/^\S[0-9]{0,3}$/;

Answer Source

Instead of regex, you can compare numerical value itself:

var ageValue = 50; // get the input age here
var ageNumericVal = +ageValue;
if (ageNumericVal < 0 || ageNumericVal > 200) {
  // invalid
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download