Email validation is passing invalid domain names with consecutive dots
- [x] I have looked at the documentation here first?
- [x] I have looked at the examples provided that may showcase my question here?
Package version eg. v9, v10:
v10
Issue, Question or Enhancement:
Email validation seems to pass invalid domain names such as
Code sample, to showcase or reproduce:
https://play.golang.org/p/V3yIIe37-1G
It seems that this behavior only works with emails which contains two or more top domains.
:heavy_check_mark: [email protected] :heavy_check_mark: [email protected] :heavy_check_mark: [email protected] :heavy_check_mark: [email protected] :negative_squared_cross_mark: [email protected] :negative_squared_cross_mark: [email protected] :negative_squared_cross_mark: [email protected] :heavy_check_mark: [email protected] :negative_squared_cross_mark: [email protected]
I replace the email regex using this one from govalidator
emailRegexString = "^(((([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(\\.([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.?$"
And I added the tests cases for this issue
s = "[email protected]"
errs = validate.Var(s, "email")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "", "", "email")
s = "[email protected]"
errs = validate.Var(s, "email")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "", "", "email")
This regex validates the multiple dots on the domain, but it doesn't pass the use case for email with underscores
s = "mail@domain_with_underscores.org"
errs = validate.Var(s, "email")
NotEqual(t, errs, nil)
AssertError(t, errs, "", "", "", "", "email")
I will try to include the underscores in this regular expression.
@kei2100 @4k1k0 yes this has been a long standing issue I just haven't had time to address yet.
I was going to change to use the regex generated here as the base. but even it doesn't;t handle all use cases so need to flesh some extra logic out with it also.