user1900662
user1900662

Reputation: 299

What is the regex pattern for all the even numbers between 2-200?

I have an input field where it will accept only numbers between 2-200 and it should be even numbers.I want the regular expression for all the even numbers between 2-200 please help.

Upvotes: 1

Views: 218

Answers (2)

anubhava
anubhava

Reputation: 785721

If you really must do via regex then this will work:

^(?!.*?[13579]$)([2-9]|[1-9][0-9]|1[0-9]{2}|200)$

Online Demo: http://regex101.com/r/mO2qI6

Upvotes: 2

NeverHopeless
NeverHopeless

Reputation: 11233

Regex is not something design to find the number in a range, you should preferably use:

if( (2 <= number <= 200) && (number %2 ==0))
{
   // doyour stuff
}

Upvotes: 3

Related Questions