I need a Javascript REGEX for Integers between 18 and 140 inclusive [closed]

When Answering your question, I am not the person to ask why you need regex for this.

And the regex you want is

/^(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, you can simply use the following code to 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));

Leave a Comment