Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Problems validating emails with dots (.) #45

Closed
diegoep opened this issue Jul 10, 2015 · 2 comments
Closed

Problems validating emails with dots (.) #45

diegoep opened this issue Jul 10, 2015 · 2 comments

Comments

@diegoep
Copy link
Contributor

diegoep commented Jul 10, 2015

When I try to put emails with dots, the validator passes when dots are in the beginning or in the end.

E.g.:
[email protected].
[email protected].
[email protected]....

@ghiscoding
Copy link
Owner

Thanks for catching this error, it seems to be so hard to find a proper regular expression that covers everything, no one as a perfect pattern for it.

So anyway, here is a better solution that I have for now, it covers most of the RFC cases, except a string inside double quotes "some string". You can test the following in your console if you want.

var pattern = /^[-\wа-яàáâãäåæçèéêëœìíïîðòóôõöøùúûñüýÿßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+(\.[-\wа-яàáâãäåæçèéêëœìíïîðòóôõöøùúûñüýÿßÞďđ0-9#~!$%^&*_=+\/`\|}{\'?]+)*@([\wа-яàáâãäåæçèéêëœìíïîðòóôõöøùúûñüýÿßÞďđ0-9_][-\wа-яàáâãäåæçèéêëœìíïîðòóôõöøùúûñüýÿßÞďđ0-9_]*(\.[-\wа-яàáâãäåæçèéêëœìíïîðòóôõöøùúûñüýÿßÞďđ0-9_]+)*([\wа-яàáâãäåæçèéêëœìíïîðòóôõöøùúûñüýÿßÞďđ]+)|(\.[\wа-яàáâãäåæçèéêëœìíïîðòóôõöøùúûñüýÿßÞďđ]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
var test1 = pattern.test("[email protected].");          // false
var test2 = pattern.test("[email protected].");         // false
var test3 = pattern.test("[email protected]....");   // false
var test4 = pattern.test("g$g.com");                // false
var test5 = pattern.test("g@g,com");                // false
var test6 = pattern.test("some [email protected]"); // false
var test7 = pattern.test("[email protected]");    // true
var test8 = pattern.test("nickname@domain");        // true
var test9 = pattern.test("кокер@спаниель.рф");      // true (russian characters)
var test10 = pattern.test("#!$%&'*+-/=?^_`{}|[email protected]");           // true
var test11 = pattern.test("[email protected]");    // true
var test12 = pattern.test("hola.àáâãäåæçèéêëœìíïîðòóôõöøùúûñüýÿ@español.com"); // true (latin characters)

// show results in console
console.log(test1); // false  [email protected].
console.log(test2); // false  [email protected].
console.log(test3); // false  [email protected]....
console.log(test4); // false  g$g.com
console.log(test5); // false  g@g,com
console.log(test6); // false  some [email protected]
console.log(test7); // true   [email protected]
console.log(test8); // true   nickname@domain
console.log(test9); // true   кокер@спаниель.рф
console.log(test10); // true  #!$%&'*+-/=?^_`{}|[email protected]
console.log(test11); // true  [email protected]
console.log(test12); // true  hola.àáâãäåæçèéêëœìíïîðòóôõöøùúûñüýÿ@español.com

// this should be valid but I can't seem to find the best way to modify my regular expression to accept double quotes and spaces inside it as shown below
// this should be valid:   "[email protected]"@example.com
// but my regular expression does not permit it yet

So apart from the double quotes ("), I have most of the other email that should be valid following the Wikipedia - email address

I am also in the process of changing some piece of my code on how I evaluate regex, so it will take me a few more days before I finish everything.

ghiscoding added a commit that referenced this issue Jul 16, 2015
- Deprecated old implentation of `regex:...:regex` (though it still
works) by a new and much better implementation of `pattern=` validator.
- Converted all the rules from string pattern to regex pattern (when
possible) defined in `angular-validation.js`.
- Also fixed issue #45 on email check.
@ghiscoding
Copy link
Owner

Fixed in latest revision #1.3.35.

Thanks for the feedback :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants