1

I am using a piece of code, from which I want to peek the selected date I am using this piece of code

<BDP:BasicDatePicker ID="Calendar1" runat="server" placeholder="DD-MM-YY"></BDP:BasicDatePicker>

and RequiredFieldValidator to check that the field is filled or not.

<asp:RequiredFieldValidator ControlToValidate="Calendar1" ID="RequiredFieldValidator3" runat="server" ErrorMessage="Must Input a date"></asp:RequiredFieldValidator>

Now I want to check if that date is well formatted or valid in format DD-MM-YY(10-Jun-2016)

Stacked
  • 6,892
  • 7
  • 57
  • 73
Ananda G
  • 2,389
  • 23
  • 39

1 Answers1

1

Use a RegularExpressionValidator with an expression like:

<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="Invalid date format. Valid dates are dd/mm/yyyy. " ControlToValidate="Calendar1" Display="None" EnableTheming="False" EnableViewState="False" SetFocusOnError="True" ValidationExpression="^(0?[1-9]|[12][0-9]|3[01])[\/](0?[1-9]|1[012])[\/]\d{4}$"></asp:RegularExpressionValidator>
Oscar
  • 13,594
  • 8
  • 47
  • 75