Regular expression for MM/DD/YYYY date textbox

Sheonarayan
Posted by Sheonarayan under ASP.NET category on | Points: 40 | Views : 2416
To force MM/DD/YYYY date in the TextBox, we can use pattern attribute of the textbox (html 5).

<input type="tex" pattern="^(0[1-9]|1[0-2])[- /.](0[1-9]|1\d|2\d|3[01])[- /.](19|20)\d{2}$" name="BOD" />


Or in ASP.NET, use asp:RegularExpressionValidator and use "^(0[1-9]|1[0-2])[- /.](0[1-9]|1\d|2\d|3[01])[- /.](19|20)\d{2}$ " regular expression as ValidationExpression.

Read more about asp:ReguarlExpressionValidator at http://www.dotnetfunda.com/tutorials/controls/regularexpressionvalidator.aspx.

Thanks

Comments or Responses

Login to post response