1

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.

user1900662
  • 299
  • 1
  • 7
  • 26
  • There is a much better way than using regex. – Cfreak Feb 20 '14 at 06:16
  • What did you try? There are several SO answers on how to find even numbers. Did you search? – Cfreak Feb 20 '14 at 06:18
  • possible duplicate of [Determine whether number is odd or even without using conditional code](http://stackoverflow.com/questions/20705184/determine-whether-number-is-odd-or-even-without-using-conditional-code) – Cfreak Feb 20 '14 at 06:22

2 Answers2

3

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
}
NeverHopeless
  • 11,077
  • 4
  • 35
  • 56
2

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

anubhava
  • 761,203
  • 64
  • 569
  • 643