Simple Javascript validation function [closed]

A function like that would look something like:

function validateNumber(n) {
  var ok = n >= 1 && n <= 17;
  if (!ok) alert('The value is not valid. Values from 1 to 17 are allowed.');
  return ok;
}

You can call it, and you get the status back if you want to use it for something:

if (validateNumber(x)) {
  // the number was valid
} else {
  // the number wasn't valid
}

Browse More Popular Posts

Leave a Comment