Riain McAtamney
Riain McAtamney

Reputation: 6432

Date Regular Expression Validator

I have a regular expression validator on a text box to validate that the text entered is a valid date.

See reg ex below:

ValidationExpression="^[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}$"

Now I want to allow the following in the textbox: mm/dd/yyyy How can I update my regex so that if mm/dd/yyyy is entered it does not throw a validation error?

Thanks in advance.

Upvotes: 2

Views: 23179

Answers (2)

Manoj
Manoj

Reputation: 1

This is a more accurate way to restrict the Date to a more meaningful format

^[1-12]{1,2}/[1-31]{1,2}/[2000-2050,1900-1999]{4}$

This is still not perfect as this will allow - for instance - a date 02/31/2013. Just realized this is quiet buggy.

Upvotes: 0

Wilco
Wilco

Reputation: 1093

ValidationExpression="^[0-9m]{1,2}/[0-9d]{1,2}/[0-9y]{4}$"

Basically allows 0-9 or m in the first field, 0-9 or d in the second, 0-9 or y in the third (in regular expression [] brackets contain a list of possible options, - denote ranges of values when placed within brackets).

Upvotes: 7

Related Questions