Javascript Form validation | set a specific input format -


i'm working on project has input field requiring user enter of following 3 options:

  1. number 150
  2. number starting 1 letter (which must n, not case sensitive) n150
  3. number ending 1 letter (which must n, not case sensitive) 150n

any other value like:

  • 150x return error message wrong input
  • x150 return wrong input
  • 1n50 return wrong position

the correct way make array of valid numbers , check if given text exists on array.
for example:

var validnumbers = [ 150, n150, 150n ];  if (validnumbers.indexof(parseint(num, 10)) >=0 ) {     //match } 

you'll need indexof function ie:

if (!array.prototype.indexof) { array.prototype.indexof = function(needle) {     for(var = 0; < this.length; i++) {         if(this[i] === needle) {             return i;         }     }     return -1; }; } 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -