...as the most complete answer, meeting the full RFC spec, though it caveats that with reasons why not to use it.
You'd be far better off not validating an email with JS at all and instead using <input type="email" /> to provide immediate user feedback and, of course, strong validation on the server receiving the input. You can still style your inputs based on valid and invalid input and the validation is done for you!
Haha, so even with 321 characters of regex it's not entirely complete.
To be clear, I'm only making the assumption that <input type="email" /> will validate perfectly to the RFC. But I'd rather leave it to a natively supplied tag than write my own either way.
It's probably worth sharing this StackOverflow link: How to validate an email in Javascript
The specific answer linked suggests:
...as the most complete answer, meeting the full RFC spec, though it caveats that with reasons why not to use it.
You'd be far better off not validating an email with JS at all and instead using <input type="email" /> to provide immediate user feedback and, of course, strong validation on the server receiving the input. You can still style your inputs based on valid and invalid input and the validation is done for you!
It doesn't completely comply to the RFC, as the RFC allows for comments and the regex does not. As one would expect with a regex.
Haha, so even with 321 characters of regex it's not entirely complete.
To be clear, I'm only making the assumption that
<input type="email" />
will validate perfectly to the RFC. But I'd rather leave it to a natively supplied tag than write my own either way.I agree. The tag is tested by millions of people, everyday, so if there were errors they would pop up.
On the other hand, I don't see the utility of comments in email addresses.
Someone, somewhere makes heavy use of comments in email addresses I bet. That one person would be positively peeved if we broke their workflow 😆