email validator is wrong
If you enter the email address: [email protected]
It says the email is valid..
Check this in this URL (from the docs):
http://docs.angularjs.org/api/ng.directive:input.email
You're not looking for email validation, you're looking for pattern validation on top of email validation --- you want valid email addresses (handled by angular) which match a specific pattern (contains a TLD)
- Would it be weird when you add pattern validation and then "your browser says it's valid and [A]ngular says it isn't"? No. So why would it be weird if that pattern validation were built in?
- We're all aware that what passes for a valid email in the use case we're interested in is narrower than the spec.
I just want to know why Angular shouldn't serve the use case I'm interested in, since it is the general case.
So why would it be weird if that pattern validation were built in?
Actually, you get the same behaviour from the browser. http://jsfiddle.net/t6rdmngo/ If you run this in a modern browser, you won't be able to submit the top form because of a pattern mismatch if you don't include a TLD.
In the angular version, you get the same behaviour. This is good. This is what we want. Identical behaviour between the native behaviour and the framework behaviour. The framework shouldn't have disagreements with the platform
Now I get it. Thanks for putting up with me!
You can quickly fix this my using ng-pattern
<input type="email" ng-pattern="/^[_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/">
If you change the last * to + in the regex it works as expected
http://w3c.github.io/html-reference/input.email.html
/^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)+$/