09 May 2010

Regular Expression for Day Month Year

Hi All,

In every application generally we need some validation for the day,month and year. Like user should only allowed to input valid date value.

Generally I am using calender control for the date. However recently I need to use some text box instead of the calender control. So I have used following validation expression for validating day,month and year.

Validation Expression for Day
^((([1-9]?)|([1-2][0-9])?)|([3][0-1]?))$

Validation Expression for Month
^((([1-9]?)|([0][1-9])?)|([1][0-2]?))$

Validation Expression for Year
[0-9]{4}

You have to place three text box for a date input and place regular expression validator against each. So in the validation expression property of the regular expression validator , use the above mentioned expression to validate proper input of each.

Hope this small tip will be useful. :)

No comments:

Post a Comment