can any one help regarding Regular expression
1) for date in format of dd/mm/yyyy which will accept date like 30/09/2017 and 01/01/2017
2) and for date format like dd-mm-yyyy
Hi Mahesh1986,
Regular expressions should not be used for date validation. This will match date like strings, which can then be validated using a proper date library if needed.
Still i am providing you the ValidationExpression.
For dd/mm/yyyy - ValidationExpression="(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/]\d{4}"
For dd-mm-yyyy - ValidationExpression="(0[1-9]|[12][0-9]|3[01])[-](0[1-9]|1[012])[-]\d{4}"
(0[1-9]|[12][0-9]|3[01]) For Day
(0[1-9]|1[012]) For Month
\d{4} For Year
[-] For -
[/] For /
HTML
<asp:TextBox runat="server" ID="txtDate1" placeholder="dd/mm/yyyy format only" /> <asp:RegularExpressionValidator ID="revDate1" ErrorMessage="DateFormat should be dd/mm/yyyy" ControlToValidate="txtDate1" runat="server" ValidationExpression="(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/]\d{4}" /> <br /> <asp:TextBox runat="server" ID="txtDate2" placeholder="dd-mm-yyyy format only" /> <asp:RegularExpressionValidator ID="revDate2" ErrorMessage="DateFormat should be dd-mm-yyyy" ControlToValidate="txtDate2" runat="server" ValidationExpression="(0[1-9]|[12][0-9]|3[01])[-](0[1-9]|1[012])[-]\d{4}" />
© COPYRIGHT 2024 ASPSnippets.com ALL RIGHTS RESERVED.