Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Nope, that regex is not that fit for the purpose. <a href="http://www.regular-expressions.info/email.html" rel="nofollow noreferrer">Have a look at this</a> instead (though I can't guarantee it's validity).<br> Also, regarding the script itself, why are you not checking like this:</p> <pre><code>function checkEmailValidity(e) { return e.match("some validating regex"); } </code></pre> <p>It seems like a faster, more consise, and more readable solution.</p> <p><strong>EDIT:</strong><br> It's worth noting, that it's almost impossible to write a regex that can detect any valid email address. Therefore, you might be better off with trying to make some validation algorithm, instead of a regex, as valid email adresses may be very, very complex.</p> <p>Consider this code:</p> <pre><code>function validateEmail(email) { if (typeof email != "string") return false; email = email.split("@"); email[1] = email[1].split("."); if ( email.length !== 2 || email[1].length &lt; 2 || !email[1].hasValues(String) ) return false; return true; } // Checks whether each key in an array has a value, and (optionally) if they match a given contructor (object type). // I.e.: myArray.hasValues(String) // checks whether all elements in myArray has a value, a nonempty string. Array.prototype.hasValues = function(assumedConstructor) { for (var i = 0; i &lt; this.length; i++) { if (!this[i]) return false; if (assumedConstructor &amp;&amp; this[i].constructor != assumedConstructor) return false; } return true; }; </code></pre> <p>It works this way:</p> <ol> <li>First checking if the string contains one <code>@</code>, and only one</li> <li>Checks that the part after the <code>@</code> has at least one <code>.</code></li> <li>Checks that there is some characters between each of the possible <code>.</code>'s.</li> </ol> <p>It will still be easy to forge a fake email address, but this way we ensure that it's at least <em>somehow</em> properly formatted. The only gotcha that I can think of, is <code>@</code>'s inside comments, which should be perfectly legal according to the RFC's, but this code will treat it as an error.<br> Normal internet users, which have normal email adresses, will not fail this. So how much it actually matters is up to you to decide ;) </p> <p>The best solution, if one is available, is to put the address into some built-in method, that somehow checks for validity by trying to use the email address.</p>
    singulars
    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. 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