Semplice
$email = '(email protected)'; $validation = filter_var($email, FILTER_VALIDATE_EMAIL); if ( $validation ) $output = 'proper email address'; else $output = 'wrong email address'; echo $output;
Avanzate
Questa funzione non solo controlla se il formato dell'indirizzo email specificato è corretto, ma esegue anche un test se l'host è esistente.
Test di espressione regolare
function checkEmail($email) ( if(preg_match("/^((a-zA-Z0-9))+((a-zA-Z0-9\._-))*@((a-zA-Z0-9_-))+((a-zA-Z0-9\._-)+)+$/",$email)) ( return true; ) return false; )
Quanto sopra, con la convalida del nome di dominio:
function checkEmail($email) ( if(preg_match("/^((a-zA-Z0-9))+((a-zA-Z0-9\._-))*@((a-zA-Z0-9_-))+((a-zA-Z0-9\._-)+)+$/",$email)) ( list($username,$domain)=split('@',$email); if(!checkdnsrr($domain,'MX')) ( return false; ) return true; ) return false; )