Email Address Validation
The Regular Expression
^[-!#$%&'*+/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+/0-9=?A-Z^_a-z{|}~])*@[a-zA-Z](-?[a-zA-Z0-9])*(\.[a-zA-Z](-?[a-zA-Z0-9])*)+$
Java Script
function validateEmail(form)
{
//Validating the email field
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
if (! form.Email.value.match(re)) {
alert("Invalid email address");
form.Email.focus();
form.Email.select();
return (false);
}
return(true);
}
C#
public static bool isEmail(string inputEmail)
{
inputEmail = NulltoString(inputEmail);
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}"
+
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\"
+
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(strRegex);
if (re.IsMatch(inputEmail))
return ( true);
else
return (false);
} ;
PHP
<?
function Verify_Email_Address($email_address)
{
//Assumes that valid email addresses consist of user_name@domain.tld
$at = strpos($email_address, "@");
$dot = strrpos($email_address, ".");
if($at === false ||
$dot === false ||
$dot <= $at + 1 ||
$dot == 0 ||
$dot == strlen($email_address) - 1)
return(false);
$user_name = substr($email_address, 0, $at);
$domain_name = substr($email_address, $at + 1, strlen($email_address));
if(Validate_String($user_name) === false ||
Validate_String($domain_name) === false)
return(false);
return(true);
}
?>
VB Script
<script language="vbscript">
function ValidateEmail(sEmail)
set myExpression = new RegExp
myExpression.pattern = "^(\w+\.)*(\w+)@(\w+\.)+([a-zA-Z]{2,4})$"
If myExpression.test(sEmail.value) = True Then
msgbox "Valid Email"
Else
msgbox "Invalid Email"
End If
End Function
</script>
<form name="email">
<input type=text name="txtEmail" maxlength=44 width=40>
<input type=button onclick="ValidateEmail(txtEmail)">
</form>