Sunday 2 February 2014

Validation for Name, Email, contact No.

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title>Validation in Asp.net</title> 
</head> 
<body> 
<form id="form1" runat="server"> 
<table cellpadding="0" cellspacing="0"> 
<tr> 
<td >Full Name<span style="color:#DA251C">*</span></td> 

<td><asp:TextBox ID="TextBox1" runat="server" TabIndex="0" MaxLength="25" ToolTip="Enter your name"></asp:TextBox>&nbsp;&nbsp; 
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required" ForeColor="#DA251C" ControlToValidate="TextBox1" Display="Dynamic" CssClass="validation" ></asp:RequiredFieldValidator> 
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="TextBox1" ValidationExpression="^[a-z A-Z]*$" ErrorMessage="Invalid Name" ForeColor="#DA251C" CssClass="validation" Display="dynamic"></asp:RegularExpressionValidator> 
</td> 

</tr> 
<tr> 
<td >Contact no<span style="color:#DA251C">*</span></td> 

<td><asp:TextBox ID="TextBox5" runat="server" MaxLength="10" ToolTip="Enter Contact no."></asp:TextBox> 
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Required" ForeColor="#DA251C" ControlToValidate="TextBox5" Display="dynamic" CssClass="validation" ></asp:RequiredFieldValidator> 
<asp:RegularExpressionValidator ID="rg" runat="server" ControlToValidate="TextBox5" ValidationExpression="^[0-9]{10}$" ErrorMessage=" Invalid No." ForeColor="#DA251C" Display="Dynamic" CssClass="validation" ></asp:RegularExpressionValidator> 
</td> 

</tr> 
<tr> 
<td >E-mail <span style="color:#DA251C">*</span></td> 

<td><asp:TextBox ID="TextBox6" runat="server" MaxLength="25" ToolTip="Enter Your Email Id"></asp:TextBox> 
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="Required" ForeColor="#DA251C" ControlToValidate="TextBox6" Display="Dynamic" CssClass="validation" ></asp:RequiredFieldValidator> 
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Invalid E-mail" ForeColor="#DA251C" ControlToValidate="TextBox6" ValidationExpression="^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z][a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$" CssClass="validation" ></asp:RegularExpressionValidator> 
</td> 

</tr> 

<tr><td colspan="2"><asp:Button ID="btn" runat="server" Text="Submit" /></td></tr> 

</table> 
</form> 
</body> 
</html>

No comments:

Post a Comment