Link to home
Start Free TrialLog in
Avatar of ayha1999
ayha1999

asked on

Regular expression

Hi,

How can validate the following format?

00 to 90 (00,10,20,30,40,50,60,70,80,90 only)-
00 to 99-
00 to 20

ayha
Avatar of rhencullen
rhencullen

For 0 to 90 use ^([0-9]0)$

For 00 - 99 use ^([0-9][0-9])$

For 00 - 20 use ^([0-9]|[1][0-9]|20)$

Paul
Avatar of ayha1999

ASKER

Hi,

the folliwng line accepts 1 without 0. can u modify it to accept only two digits like 01,02 ... 20?

thanks

ayha
The following revision:

^(0[0-9])$|^(1[0-9])$|^(20)$

Will only accept 2-digit numbers from 00 to 20.

Broken down as:

First Character 0 with a second character between 0 to 9,
OR
First character 1 with a second character between 0 to 9
OR
the number 20.

Paul


You can also write the above as:

^(0[0-9])|(1[0-9])|(20)$

Paul
ASKER CERTIFIED SOLUTION
Avatar of rhencullen
rhencullen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial