Validar e-mail:
function verify_email($email){
if(!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/',$email)){ return false;
} else {
return $email;
}
}
function EmailValidation($email)
{
if ( eregi ( '[a-z||0-9]@[a-z||0-9].[a-z]', $email ) ) { //checks to make sure the email address is in a valid format
$domain = explode( "@", $email ); //get the domain name if ( @fsockopen ($domain[1],80,$errno,$errstr,3)) {
//if the connection can be established, the email address is probably valid
return true;
} else
{
return false; //if a connection cannot be established return false
}
return false; //if email address is an invalid format return false
}
}
function validar_email($email) {
$pattern_local = '^([0-9a-z]*([-|_]?[0-9a-z]+)*)(([-|_]?)\.([-|_]?)[0-9a-z]*([-|_]?[0-9a-z]+)+)*([-|_]?)$';
$pattern_domain = '^([0-9a-z]+([-]?[0-9a-z]+)*)(([-]?)\.([-]?)[0-9a-z]*([-]?[0-9a-z]+)+)*\.[a-z]{2,4}$';
$match_local = eregi($pattern_local, $local); $match_domain = eregi($pattern_domain, $domain);
if ($match_local && $match_domain) {
return 1;
} else {
return 0;
}
}
En PHP 5:
Se añade la funcionalidad de filter_var
if(filter_var("prueba@dominio.com", FILTER_VALIDATE_EMAIL
)){ echo "Ok";
} else {
echo "Error";
}
Usando filter _var y comprobando que tenga un punto el dominio con una expresión regular:
function validateEmailAddress($email) {
}
Ejemplo Wordpress (usando expresiones regulares)
function is_email($email) {
return false;
}
if( strpos( $email, '@', 1 ) === false ){ return false;
}
if( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ){ return false;
}
return false;
}
if( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ){ return false;
}
if( 2 > count( $subs ) ){ return false;
}
foreach ( $subs as $sub ) {
if( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ){ return false;
}
return false;
}
}
return true;
}
Verificar e-mail mirando registro MX si es válido, útil para separar nombre y dominio de un e-mail
function verify_email_dns($email){
// This will split the email into its front
// and back (the domain) portions
// No MX record found
return false;
} else {
// MX record found, return email
return $email;
}
}
$string = 'some_name@somedomain.com';
// array
echo $res[0];
$name = $res[0];
echo $name;
substr
$mail = "some_name@somedomain.com";
explode
echo $name;