Hello Guys,
Here I am going to explain you the little about some regular expression validator. What we used in our daily life.
Here is an example:
Here I am going to explain you the little about some regular expression validator. What we used in our daily life.
Here is an example:
<div>
<table cellpadding="4" cellspacing="0" width="50%">
<tr><td>Name</td><td><asp:TextBox ID="txtName"
runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="revName" runat="server"
ControlToValidate="txtName"
ValidationGroup="vgSave"
ValidationExpression="^[a-zA-Z]+$"
ErrorMessage="Please
enter valid name"></asp:RegularExpressionValidator></td></tr>
<tr><td>Age</td><td><asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="revAge" runat="server"
ControlToValidate="txtAge"
ValidationGroup="vgSave" ValidationExpression="\d{2}"
ErrorMessage="Please enter valid
age"></asp:RegularExpressionValidator></td></tr>
<tr><td>Telephone</td><td><asp:TextBox ID="txtTelephone"
runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="revTelephone" runat="server"
ControlToValidate="txtTelephone"
ValidationGroup="vgSave" ValidationExpression="\d{10}"
ErrorMessage="Please enter valid (10)
digit phone no."></asp:RegularExpressionValidator></td></tr>
<tr><td>Birth Date</td><td><asp:TextBox ID="txtBirthDate"
runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="revBirthDate" runat="server"
ControlToValidate="txtBirthDate"
ValidationGroup="vgSave" ValidationExpression="^(0[1-9]|[12][0-9]|3[01])[-
/.](0[1-9]|1[012])[- /.](19|20)\d\d$"
ErrorMessage="Please enter valid Date
of Birth (dd/mm/yyyy)."></asp:RegularExpressionValidator></td></tr>
<tr><td><asp:Button ID="btnSave" runat="server" Text="Save" ValidationGroup="vgSave" /></td>
<td><asp:Button ID="btnCancel" runat="server" Text="Cancel" /></td>
</tr>
</table>
</div>
Comments