Tuesday 9 July 2013

Programmatically Checking Regular Expression Condition for DateTime Format(MM/DD/YYYY)

 <asp:TextBox ID="textbox1"  runat="server"/>

 <asp:Button ID="btnmatch" runat="server" Text="Result"
                        onclick="btnmatch_Click" />

 protected void btnCalculate_Click(object sender, EventArgs e)
    {
    string date = textbox1.text;
     Regex regex = new Regex(@"^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$");
        Match match = regex.Match(date);
        if (match.Success)
            {
           MessageBox.Show("Matched Regex condition");
            }
       else
          {
             MessageBox.Show("Does not Matched Regex condition");
           }
   }