Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Validating emails is <em>hard</em>. The fully correct regex is a true monstrosity that you can see (if you dare) at <a href="http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html" rel="nofollow noreferrer">http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html</a> which <em>probably</em> isn't what you want.</p> <p>Instead, you have a few options. Use a regex that matches 99% of emails, do it server side with an email validation library, or implement a finite state machine to parse it correctly. The state machine is probably too bulky (although allows neat stuff like suggestions for possible typos) and doing it all server side -- which you better be doing anyway (what if someone has JavaScript disabled?) -- loses the benefits of as-you-type checking.</p> <p>That leaves a simpler regex that doesn't match all legal emails, but matches enough that the chances of someone registering with one that it doesn't are really slim. The regex from <a href="https://stackoverflow.com/questions/46155/validate-email-address-in-javascript">Validate email address in JavaScript?</a> should do the trick pretty well:</p> <pre><code>/^(([^&lt;&gt;()[\]\\.,;:\s@\"]+(\.[^&lt;&gt;()[\]\\.,;:\s@\"]+)*)|(\ ".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA -Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ </code></pre> <p>Also, you made a small typo:</p> <pre><code>else if(!email.test('#email')) { $('#emailErrorMsg').text("OK"); } </code></pre> <p>is testing against the string '#email' -- not the element with the ID 'email'. Change that to:</p> <pre><code>else if(!email.test($('#email').val())) { $('#emailErrorMsg').text("OK"); } </code></pre>
    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. 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