开发者

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.


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜