raklos
raklos

Reputation: 28545

regex help for validators

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?

Upvotes: 0

Views: 107

Answers (3)

JaredPar
JaredPar

Reputation: 754725

00-31 case

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

01-12 case

"^(0?[1-9])|(10)|(11)|(12)$"

Upvotes: 0

f0b0s
f0b0s

Reputation: 3097

1920-2009:

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

Upvotes: 1

Podge
Podge

Reputation: 467

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.

Upvotes: 2

Related Questions