Since erigi()
is deprecated in PHP 5 and I am in a need to validate an e-mail id , so which function should be used...? further please give the format for e-mail validation such as:
<?php
function checkEmail($email)
{
if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email))
{
return FALSE;
}
list($Username, $Domain) = split("@",$email);
if(getmxrr($Domain, $MXHost))
{
return TRUE;
}
else
{
if(fsockopen($Domain, 25, $errno, $errstr, 30))
{
return TRUE;
}
else
{
return FALSE;
}
}
}
?>
For php 5.2: http://php.net/manual/en/function.filter-var.php
$result = filter_var($email , FILTER_VALIDATE_EMAIL);
Or http://pl.php.net/manual/en/function.preg-match.php for any regular expression.
Use the filter_var
PHP function instead:
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
}
Or, even better yet, use a RFC-compliant email address validator. As no amount of regex will encompass all the valid emails that are possible.
En example with with filter extension.
<?php
function is_valid_email($email)
{
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}
var_dump(is_valid_email('test@example.com'));
var_dump(is_valid_email('foobar'));
var_dump(is_valid_email('test+foo@example.com.com'));
[~]> php x.php
bool(true)
bool(false)
bool(true)
This you can then combine with further validation that you already have.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.