ASP.NET: Email Validation by RegularExpressionValidator

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

3 comments:

  1. There are huge collections of regular expression patterns living on the Internet. My
    favorite website for finding regular expressions is http://regexlib.com/

    ReplyDelete
  2. regex pattern

    "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";

    http://asp.net-informations.com/communications/asp-email-validation.htm

    gail

    ReplyDelete
  3. Hi there, checked the code an enhanced version here - https://www.mailcheck.co/
    Check their API

    ReplyDelete