Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use different E-Mail regex #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

markus1189
Copy link

@markus1189 markus1189 commented Feb 15, 2021

As noted in #57, the current Regex is broken for Emails like:

foo.bar+mysuffix@gmail.com

Therefore, exchange the used regex with the one from emailregex.com.

As noted in valiktor#57, the current Regex is broken for Emails like:

```
foo.bar+mysuffix@gmail.com
```

Therefore, exchange the used regex with the one from emailregex.com.
@@ -479,7 +479,8 @@ fun <E> Validator<E>.Property<String?>.doesNotEndWithIgnoringCase(suffix: String
fun <E> Validator<E>.Property<String?>.isEmail(): Validator<E>.Property<String?> =
this.validate(Email) {
it == null || it.matches(
Regex("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
// see https://emailregex.com/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we dont need to keep this comment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the comment is pretty important, because it's easier to go to emailregex.com and read the documentation of the Regex instead of trying to figure out if the given regex makes sense 😉

@@ -479,7 +479,8 @@ fun <E> Validator<E>.Property<String?>.doesNotEndWithIgnoringCase(suffix: String
fun <E> Validator<E>.Property<String?>.isEmail(): Validator<E>.Property<String?> =
this.validate(Email) {
it == null || it.matches(
Regex("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
// see https://emailregex.com/
Regex("""(?:[a-z0-9!#${'$'}%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#${'$'}%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])""")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${'$'} is this necessary? cant we just scape the $ character?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure anymore, this pr is already pretty old and to be honest we have moved on and I don't care too much about this anymore

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

Successfully merging this pull request may close these issues.

None yet

2 participants