Validate Date in dd/MM/yyyy format


Sometime we need to validate our control for proper date format in dd/MM/yyyy format. Below is the code snippet for that. Main part of code snippet is the Regular expression i used to validate.

<asp:TextBox ID=”txtDate” runat=”server”></asp:TextBox>

<asp:RegularExpressionValidator ID=”revDTTest” runat=”server” ControlToValidate=”txtDate” ForeColor=”Red”
ErrorMessage=”Enter Valid Date in dd/mm/yyyy format.” SetFocusOnError=”True” Display=”Dynamic”
ValidationExpression=”(^((((0[1-9])|([1-2][0-9])|(3[0-1]))|([1-9]))\x2F(((0[1-9])|(1[0-2]))|([1-9]))\x2F(([0-9]{2})|(((19)|([2]([0]{1})))([0-9]{2}))))$)“></asp:RegularExpressionValidator>

Advertisements

3 thoughts on “Validate Date in dd/MM/yyyy format

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s