Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a function that I use. It does a little more than just run the email address through a regex, but so far it is the most complete solution that I found:</p> <pre><code>function validEmail($email, $skipDNS = false) { $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) &amp;&amp; !$atIndex) { $isValid = false; } else { $domain = substr($email, $atIndex+1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen &lt; 1 || $localLen &gt; 64) { // local part length exceeded $isValid = false; } else if ($domainLen &lt; 1 || $domainLen &gt; 255) { // domain part length exceeded $isValid = false; } else if ($local[0] == '.' || $local[$localLen-1] == '.') { // local part starts or ends with '.' $isValid = false; } else if (preg_match('/\\.\\./', $local)) { // local part has two consecutive dots $isValid = false; } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { // character not valid in domain part $isValid = false; } else if (preg_match('/\\.\\./', $domain)) { // domain part has two consecutive dots $isValid = false; } else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&amp;`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { // character not valid in local part unless // local part is quoted if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isValid = false; } } if(!$skipDNS) { if ($isValid &amp;&amp; !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) { // domain not found in DNS $isValid = false; } } } return $isValid; } </code></pre> <p>The function has an <strong>optional $skipDNS argument</strong> that can be set to TRUE if you don't want to validate the MX records for the hos. Otherwise the function will attempt to validate that the e-mail address provided actually maps to a real email server.</p> <p>It's useful to note that most RegEx email validation techniques will validate most e-mail addresses but they will most likely allow some carefully crafted invalid addresses or worst.. fail on some more obscure, but valid e-mail addresses. For more information you may want to check out the <a href="http://tools.ietf.org/html/rfc2822" rel="noreferrer">Internet Message Formats RFC</a> which describes the allowed format for e-mail addresses.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload