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

Yeah you're right, it looks like EMAIL_REGEX is wrong.

According to http://dev.w3.org/html5/markup/input.email.html, we can use

/^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/

and that looks like it should work better due to not including the . following the @

I'll try submitting a quick patch for this.

... actually, this is a bit more complicated than I thought it would be, this might take a bit more work. It looks like it will also accept regexps which begin with a period, too. So there's a bit of work to do here I guess.

If you can solve this before me, feel free to submit a pull request

caitp avatar Jan 22 '14 00:01 caitp

Thanks for the bug report. On the docs demo, you won't notice this fix until 1.2.10 drops, because it loads the 1.2.9 angular script all the time. But in a few days you should see this addressed on the doc demo (unless the commit gets reverted, which could happen O_O)

caitp avatar Jan 22 '14 03:01 caitp

Great, 10x!

On Wed, Jan 22, 2014 at 5:32 AM, Caitlin Potter [email protected]:

Thanks for the bug report. On the docs demo, you won't notice this fix until 1.2.10 drops, because it loads the 1.2.9 angular script all the time. But in a few days you should see this addressed on the doc demo

— Reply to this email directly or view it on GitHubhttps://github.com/angular/angular.js/issues/5899#issuecomment-32990587 .

ofirdagan avatar Jan 22 '14 11:01 ofirdagan

What was my facial expression when I noticed that "dummy@ferferfe" (without any domain) is considered as a valid mail ;)

mica16 avatar Jan 29 '14 00:01 mica16

@mica16 but dummy@ferferfe is a valid email address. Domains don't need to have an extension, just think about localhost.

Zequez avatar Feb 13 '14 17:02 Zequez

@Zequez correct, but who the hell uses a localhost address for a websites registration in example?

mbeckenbach avatar Feb 16 '14 12:02 mbeckenbach

@mbeckenbach Use ng-pattern="/^[a-z0-9!#$%&'*+/=?^_`{|}~.-]+@[a-z0-9-]+.[a-z0-9-]/" Not ideal but works.

DracoThuban avatar Feb 16 '14 13:02 DracoThuban

@mbeckenbach yeah, true. But consider that a domain name without dots is a valid domain. That ICANN won't let you register a domain with THEM, doesn't mean that the domain name is invalid.

Zequez avatar Feb 17 '14 04:02 Zequez

6@6 is not an email address. The fact that it could be a proper email address in a special circumstance shouldn't, in my opinion, lead us to permit it. The odds of a mistake getting through via this permissive pattern are orders of magnitude greater than the odds that we'll exclude someone with such an email address.

jeffmcmahan avatar Feb 22 '14 23:02 jeffmcmahan

+1 for Jeff

mica16 avatar Feb 22 '14 23:02 mica16

@jeffmcmahan I'm sorry but it sounds like you should file an issue with the IETF or the WHATWG. Once the definition of what an email address looks like changes, then it should be changed in Angular, but we really need to follow what is described in the RFCs and WHATWG recommendations.

Now, if you do want to be a bit more strict, you could also add a pattern validator, that would be fine.

caitp avatar Feb 23 '14 00:02 caitp

@caitp You're the boss.

jeffmcmahan avatar Feb 23 '14 00:02 jeffmcmahan

How about making the EMAIL_REGEXP configurable? Our server side validation is stricter than the angularjs one. Specifically, it requires, e.g., that the part before the @ sign is not longer than 63 characters. Now we have to create a custom directive for all email inputs or remember to add the ng-pattern to each email input.

rjokelai avatar May 08 '14 06:05 rjokelai

you can use ng-pattern in addition to type=email, @rjokelai -- also, @matsko's validation pipeline change will make it easier to add custom email validation

caitp avatar May 08 '14 14:05 caitp

"Now, if you do want to be a bit more strict, you could also add a pattern validator, that would be fine."

how about the default validator only accepts normal emails with a dot in them, and if someone in the tiny minority wants to be less strict, they can make their own validator. Why should the vast majority of devs need to make their own pattern just so the tiny minority doesnt have to? This is silly standards purism

omasback avatar May 24 '14 03:05 omasback

because this is basically a polyfill for html5 constraint validation, that's why. Next week we'll hopefully be shipping a feature that will make customizing this much easier

caitp avatar May 24 '14 04:05 caitp

Are emails without domain zone valid? I'm testing simple input field with type="email" and Angular validates foo@bar email succesfully. (Angular v1.3.0)

Oh, there is a closed issue already — https://github.com/angular/angular.js/issues/9463

artuska avatar Oct 22 '14 18:10 artuska

Are emails without domain zone valid? I'm testing simple input field with type="email" and Angular validates foo@bar email succesfully. (Angular v1.3.0)

They are valid emails, per spec. This question has been answered so many times on this issue tracker, there is nothing invalid about an email without a TLD.

Use a custom validator to require the specific TLDs you want

caitp avatar Oct 22 '14 18:10 caitp

@caitp, I realize we've been hassling you about this, but I think it could be helpful if you explained why keeping to the spec is imperative. We all recognize that a reasonable and competent developer is not going to assume that the email validator allows 0@0. That is to say, it's going to be used for the standard form registration situation, and it's going to cause problems in many such situations. And we're told that the importance of keeping to the spec outweighs those problems. Okay---cool. But why?

jeffmcmahan avatar Oct 22 '14 18:10 jeffmcmahan

Because it's going to be really weird when your browser says it's valid and angular says it isn't

caitp avatar Oct 22 '14 18:10 caitp