CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Eric Wise

Business & .NET

IsEmailAddress

Short, sweet, and to the point.

    Protected Function IsEmailAddress(ByVal Address As String) As Boolean
        Return System.Text.RegularExpressions.Regex.IsMatch(Address, "^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$")
    End Function


Comments

Eric Wise said:

Like most snippets there's a story behind this one.

The system I was working on had a SQL server based messaging system that emulates email, except the user requirement is that it is a closed system.

Now, in the effort to support an Outlook style feel I set it up so users could create contacts, and put those contacts into groups. The IsEmailAddress function you see here was a check when parsing the To: CC: or BCC: fields using a split(";") command. Since they could type in a group name or an "email" address I used this function to check to see whether it was an "email" address or a group.
# April 1, 2005 3:26 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!