Pages

Showing posts with label asp:RegularExpressionValidator. Show all posts
Showing posts with label asp:RegularExpressionValidator. Show all posts

Monday, September 16, 2013

REGEX for Time format (hh:mm)

REGEX for "hh:mm" is:

^(1[0-2]|0[1-9]):([0-5][0-9])$

Using this Regex pattern, user can enter the Hours between 01-12 & Minutes between 00-59,  with the Separator ':'

Use this code :

"txt_time" textbox takes time as input.

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

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" Display="None"
  ErrorMessage="Enter Valid Time(HH:mm)" ValidationExpression="^(1[0-2]|0[1-9]):([0-5][0-9])$"
  ValidationGroup="headlink" ControlToValidate="txt_time">

</asp:RegularExpressionValidator>






<asp:ValidationSummary ID="ValidationSummary2" CssClass="erroesummary" runat="server" ValidationGroup="headlink" HeaderText="The Following Fields Are Mandatory :" ShowMessageBox="false" DisplayMode="BulletList" ShowSummary="true" />


<asp:Button ID="btn" runat="server" OnClick="btn_Click"
                                    ValidationGroup="headlink" />



Results:


12:59        Correct
11:61        Incorrect
01:01        Correct
01*01       Incorrect
09:88        Incorrect

 

Sunday, September 15, 2013

REGEX to validate the Date (mm/dd/yyyy) - C#


 The format for Date is: mm/dd/yyyy .


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


  <asp:RegularExpressionValidator ID="rdate" runat="server" Display="None" ErrorMessage="Enter Valid Date"

ValidationExpression="^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$" 
ValidationGroup="headlink" 
ControlToValidate="txtdate">
</asp:RegularExpressionValidator>