Simple Email Address validation control

found this here:

http://vaultofthoughts.net/CategoryView,category,ASP.NET.aspx
lifted and duplicated below – so I do not lose it 🙂
“…. the EmailValidator control which validates user input with a pattern of an email:

public class EmailValidator

    : RegularExpressionValidator

{

    public EmailValidator()

    {

        ValidationExpression =

        @”^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@

        [a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.

        [a-zA-Z][a-zA-Z\.]*[a-zA-Z]$”;

        ErrorMessage = “Email is incorrect”;

    }

}

“Note that ValidationExpression is broken so it may be better displayed in the browser. As for how accurate, the expression is. It was taken from the Regular Expression Library page and I have had no problems with it.

Usage on a page after registration:”

<my:EmailValidator runat=”server” ID=”EmailCorrect”

    ControlToValidate=”Email” />

Advertisements