[Solved] How do I restrict special characters except underscore, hyphen and dot in email field in PHP? [duplicate]


Use a RegEx like this:

/^[\w\.]+@/

Then you should also check if the domain really exists.

PHP:

$regex = "/^[\w\.]+@/";
$email = emailField($_POST['email']);

$domain = preg_replace($regex, '', $email); //get the domain of the email address by removing the local-part

//Using checkdnsrr we are checking if this domain is registred
if($email == '' && preg_match($regex, $email) && checkdnsrr($domain)){
  echo "Valid";
}

See also: http://php.net/manual/en/function.checkdnsrr.php

1

solved How do I restrict special characters except underscore, hyphen and dot in email field in PHP? [duplicate]