I need a Javascript REGEX for Integers between 18 and 140 inclusive -


i'm still trying find way around javascript regular expressions, , have not been able deduce how write regex need.

please need javascript regex age. want allow between ages 18 , 140. 18 being allowed , 140 being allowed. want regex accepts 18,19,20,21,...138,139,140. , this.

i'd appreciate help.

p.s. hope simple answer without stack overflow closing question down , saying 'duplicate' or or that... if not might last question on stack overflow, because sadly, seems stack overflow making harder ask simple question. point want ton of research...or @ least lot, before ask question. though many times ask questions precisely because don't have the time lot of research. :: sigh ::

when answering question, not person ask why need regex this.

and regex want

/^(1[89]|[2-9][0-9]|1([0-3][0-9]|40))$/ 

sample

var age=/^(1[89]|[2-9][0-9]|1([0-3][0-9]|40))$/;    console.log(age.test(18));  console.log(age.test(140));  console.log(age.test(12));  console.log(age.test(142));

but, can use following code test

if(age>=18 && age<=140) 

that is

function test(age){    return age>=18 && age<=140;  }    console.log(test(18));  console.log(test(140));  console.log(test(12));  console.log(test(142));


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -