Skip to content

Commit

Permalink
Merge pull request #396 from prasunjoshi/emailvalidator
Browse files Browse the repository at this point in the history
IsExistingEmail refactor code and test
  • Loading branch information
asaskevich committed Aug 17, 2020
2 parents 8b91a60 + c8310ec commit 26e826e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ func IsExistingEmail(email string) bool {
if len(user) > 64 {
return false
}
if userDotRegexp.MatchString(user) || !userRegexp.MatchString(user) || !hostRegexp.MatchString(host) {
return false
}
switch host {
case "localhost", "example.com":
return true
}
if userDotRegexp.MatchString(user) || !userRegexp.MatchString(user) || !hostRegexp.MatchString(host) {
return false
}
if _, err := net.LookupMX(host); err != nil {
if _, err := net.LookupIP(host); err != nil {
return false
Expand Down
4 changes: 4 additions & 0 deletions validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,10 @@ func TestIsExistingEmail(t *testing.T) {
{"@invalid.com", false},
{"NathAn.daVIeS@DomaIn.cOM", true},
{"NATHAN.DAVIES@DOMAIN.CO.UK", true},
{"prasun.joshi@localhost", true},
{"[prasun.joshi]@DomaIn.cOM", false},
{"sizeofuserismorethansixtyfour0123sizeofuserismorethansixtyfour0123@DOMAIN.CO.UK", false},
{"nosuchdomain@bar.nosuchdomainsuffix", false},
}
for _, test := range tests {
actual := IsExistingEmail(test.param)
Expand Down

0 comments on commit 26e826e

Please sign in to comment.