views:

74

answers:

3

I need a regular expression validator to validate that text fields contain only numbers between 00 - 31 (note that it should allow both 05 and 5), another regex for numbers 01 -12 (again, it should allow both 05 and 5), and another regex for numbers between 1920 - 2009.

How can i do this?

A: 

00-31 case

"^(0?[0-9])|([1-2][0-9])|(30)|(31))$"

01-12 case

"^(0?[1-9])|(10)|(11)|(12)$"
JaredPar
there is an error, isn`t it? "^(0?[1-9])|(10)|(11)|(12)$"
f0b0s
Your second expression does not match 11.
apathetic
and it matches 00 and 0.
f0b0s
@apathetic, changed it to match 11
JaredPar
why do you need (01)?
f0b0s
@f0b0s.iu9.info, I don't. I was being overcareful in my original answer.
JaredPar
+2  A: 

What not use the range validator and put the min and max dates in with a datatype of Date. So minValue= 1/1/1920, maxValue= 1/12/2009. You can even set the maxvalue on a page load (no postback check) with todays date.

Podge
+1  A: 

1920-2009:

"^(19[2-9][0-9])|(200[0-9])$" or simplier: "^((19[2-9])|(200))([0-9])$"
f0b0s