Semantic-Org / Semantic-UI

Semantic is a UI component framework based around useful principles from natural language.
http://www.semantic-ui.com
MIT License
51.12k stars 4.94k forks source link

[Form validation] Built-in email rule says 'bad@email' is a valid email. #5124

Open kmd1970 opened 7 years ago

kmd1970 commented 7 years ago

I entered bad@email while testing form validation using the built-in email rule and it came back as valid. Is this a bug? I would say the bad@email is not a valid email.

mfeherpataky commented 7 years ago

While it seems that bad@mail is bad indeed, it turns out that it is a valid email address. Top Level Domain is still a domain. Email validation - trivial on the surface - gets more complicated the closer the edge is. Some reading - I Knew How To Validate An Email Address Until I Read The RFC & Stop Validating Email Addresses With Regex.

harogaston commented 7 years ago

Well as @mfeherpataky said, as per RFC 2822 bad@email is in fact a valid address. However, it could be a sensible approach to validate at least a trailing domain, so .+@.+\..+ would suffice.

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

TwistedLogic commented 6 years ago

Although bad@email is a valid email address for the RFC 5321, according to RFC 5322 the following regex should better suit our everyday use (source):

^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\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,}))$
certainlysylvia commented 6 years ago

How about just adding a flag for whether it is strict - per RFC 5321 validation or less-strict, aka, practical - per RFC 5322

Then it is right for all contexts.

y0hami commented 6 years ago

I don't see why this is an issue if you want to use RFC 5322 then you can just specify a custom regex rule.