Sunday 2 February 2014

Watermark on TextBox

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Validation in Asp.net</title>

<script type="text/javascript" language="javascript">
<!--
function doClear(theText) {
if (theText.value == theText.defaultValue) {
theText.value = ""
}
}

function doClear1(theText) {
if (theText.value == "") {
theText.value = theText.defaultValue
}
}
//-->
</script>

</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" MaxLength="25" Text="Enter Name" onFocus="doClear(this)" onblur="doClear1(this)"></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" Text="Enter Contact" onFocus="doClear(this)" onblur="doClear1(this)" ></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" Text="Enter Email" onFocus="doClear(this)" onblur="doClear1(this)"></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