angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

email validator is wrong

Open ofirdagan opened this issue 12 years ago • 26 comments

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

ofirdagan avatar Jan 20 '14 17:01 ofirdagan

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)

caitp avatar Oct 22 '14 18:10 caitp

  1. 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?
  2. 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.

jeffmcmahan avatar Oct 22 '14 19:10 jeffmcmahan

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

caitp avatar Oct 22 '14 19:10 caitp

Now I get it. Thanks for putting up with me!

jeffmcmahan avatar Oct 22 '14 20:10 jeffmcmahan

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})$/">

steelx avatar Nov 16 '15 09:11 steelx

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-]+)+$/

martinpagesaal avatar Sep 03 '20 14:09 martinpagesaal