RegularExpressionValidator for email address

Gopesh9
Posted by Gopesh9 under ASP.NET category on | Points: 40 | Views : 1213
<%@ Page Language="C#" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Show RegularExpressionValidator</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Label
id="lblEmail"
Text="Email Address:"
AssociatedControlID="txtEmail"
Runat="server" />
<asp:TextBox
id="txtEmail"
Runat="server" />
<asp:RegularExpressionValidator
id="regEmail"
ControlToValidate="txtEmail"
Text="(Invalid email)"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
Runat="server" />

<br /><br />

<asp:Button
id="btnSubmit"
Text="Submit"
Runat="server" />

</div>
</form>
</body>
</html>

Comments or Responses

Posted by: Srilu.Nayini577 on: 8/6/2012 Level:Starter | Status: [Member] | Points: 10
Hi,
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server"
style="z-index: 1; left: 315px; top: 114px; position: absolute" Text="Email"></asp:Label>

<asp:TextBox ID="txtemail" runat="server"
style="z-index: 1; left: 437px; top: 107px; position: absolute"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtemail" ErrorMessage="Invalid email"
style="z-index: 1; top: 114px; position: absolute; left: 658px"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
style="z-index: 1; left: 398px; top: 214px; position: absolute; right: 483px"
Text="Button" />

</div>

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


Thank you,

Login to post response