sandykadam
202.***.***.***E-mail validation in PHP (Simple function w/ regex)
PHP code:
<?php
// Function to validate an email address
function emailValidate($Email)
{
if (preg_match("/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/", $Email))
{
return 1;
}
else
{
return 0;
}
}
// Example usage - displays the appropriate message depending on whether the e-mail address is valid.
$email = “sandy@example.com”;
if(emailValidate($email))
{
echo 'The given e-mail address is valid.';
}
else
{
echo 'The given e-mail address is NOT valid.';
}
?>