1. Confirm valid e-mail format
The following code example uses the static Regex.IsMatch method to verify whether a string is a valid e-mail format. If the string contains a valid e-mail address, the IsValidEmail method returns True, otherwise it returns false without taking any other action. You can use IsValidEmail to filter e-mail addresses that contain invalid characters before an application stores the address in a database or displays it in a asp.net page.
Visual Basic code example
Function IsValidEmail (Strin as String) as Boolean
' Return True if
Strin are in valid e-mail format.
Return Regex.IsMatch (Strin, ("^ [w.] +) @
([[[0-9]{1,3}.[ 0-9]{1,3}. [0-9] {1,3}.) |
(([w-]+.) +)) ([a-za-
z]{2,4}| [0-9] {1,3}) (]?) $")
End Function
C # code example
BOOL IsValidEmail (String strin)
{
Return true if Strin are in
valid e-mail format.
Return Regex.IsMatch (Strin, @ "^" ^ [W.] +) @ ([[0-9]{1,3}. [0
-9]
{1,3}. [0-9] {1,3}.) | (([w-]+.) +)) ([a-za-z]{2,4}| [0-9] {1,3}) (]?)
$");
}