ASP.Net/Validation by Function/Email

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

asp:RegularExpressionValidator for email address (C#)

<%@ 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>



Validating an Email Address with a RegularExpressionValidator Control (VB.net)

<%@ Page Language=VB Debug=true %>
<HTML>
<HEAD>
<TITLE>Validating an Email Address with a RegularExpressionValidator Control</TITLE>
</HEAD>
<form runat="server">
<BR><BR>
Please enter an email address:<BR>
<asp:textbox 
    id="txtEmail" 
    runat=server 
/>
<asp:regularexpressionvalidator 
    id="regEmail"
    controltovalidate="txtEmail"
    validationexpression="\w+\w*\@\w+\w+\w*\.(com|edu|org|gov)"
    display="Dynamic"
    font-name="Arial" 
    font-size="11"
    runat=server
>
    You must enter an email address in the form of me@na.ru.
</asp:regularexpressionvalidator>
<BR><BR>
<asp:button 
    id="butOK"
    text="OK"
    type="Submit"
    runat="server"
/>
</form>
</BODY>
</HTML>