From 90c99620698fee34128a9be757707f72a033206d Mon Sep 17 00:00:00 2001 From: Juke-Duke Date: Tue, 7 Feb 2023 23:44:32 -0500 Subject: [PATCH 01/16] Contributed EmailAddress Scalar --- .../contributed/Juke-Duke/email-address.md | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 scalars/contributed/Juke-Duke/email-address.md diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md new file mode 100644 index 0000000..0dfa9bc --- /dev/null +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -0,0 +1,89 @@ +# EmailAddress — GraphQL Custom Scalar + +Author - Juke-Duke + +Date - 2023-02-06 + +This is a String-based Scalar. + +**License and Copyright** + +Copyright © GraphQL contributors. This specification is licensed under +[OWFa 1.0](https://www.openwebfoundation.org/the-agreements/the-owf-1-0-agreements-granted-claims/owfa-1-0). + +# Overview + +This Scalar represents a valid electronic mail address using a simplified version of [RFC 5322](https://www.rfc-editor.org/rfc/rfc5322). + +The format of an email address is `local@domain`, where the local part may consist of up to 64 UTF-8 characters, the domain part may consist of up to 255 UTF-8 characters, and the two parts are separated by an `@` sign. + +Other formats, including using square-bracketed IP addresses in the domain part, and quoted-string local parts, are not supported for simplicity. + +The local part may contain any of the following ASCII characters: +- Uppercase and lowercase Latin letters `A` to `Z` and `a` to `z` +- Digits `0` to `9` +- Printable characters ``!#$%&'*+-/=?^_`{|}~`` +- Dot `.`, provided that it is not the first or last character and provided also that it does not appear consecutively + +The domain part may contain any of the following ASCII characters: +- Uppercase and lowercase Latin letters `A` to `Z` and `a` to `z` +- Digits `0` to `9`, provided that top-level domain names are not all-numeric (.com, .net, .org, etc.) +- Hyphen `-`, provided that it is not the first or last character + +**Examples** + +The general format is described in [RFC5322 Section 3.4.1](https://www.rfc-editor.org/rfc/rfc5322#section-3.4.1). +These examples are taken from [WikiPedia](https://en.wikipedia.org/wiki/Email_address#Examples), which is also based off of [RFC5322 Section 3.4.1](https://www.rfc-editor.org/rfc/rfc5322#section-3.4.1). + +These are valid eamples: + +| String | Explanation | +| ------------------------------------------------ | --------------------------------------------------------------------- | +| `simple@example.com` | An EmailAddress without any special characters. | +| `very.common@example.com` | An EmailAddress with a dot inside the local part. | +| `disposable.style.email.with+symbol@example.com` | An EmailAddress with dots and a plus sign inside the local part. | +| `other.email-with-hyphen@example.com` | An EmailAddress with a dot and hyphens inside the local part. | +| `fully-qualified-domain@example.com` | An EmailAddress with hypehns inside the local part. | +| `user.name+tag+sorting@example.com` | An EmailAddress with a dot and plus signs inside the local part | +| `x@example.com` | An EmailAddress with a single character in the local part. | +| `example-indeed@strange-example.com` | An EmailAddress with a hyphen in both the local and domain parts. | +| `test/test@test.com` | An EmailAddress with a slash in the local part. | +| `admin@mailserver1` | An EmailAddress with no top-level domain. This is highly discouraged. | +| `example@s.example` | An EmailAddress with a dot in the domain part. | +| `mailhost!username@example.org` | An EmailAddress with a bang in the local part. | +| `user%example.com@example.org` | An EmailAddress with a percent sign in the local part. | +| `user-@example.org` | An EmailAddress with a hyphen in the local part. | + +These are invalid examples: +| String | Explanation | +| -------------------------------------------------------------------------------- | -------------------------------------------------------------- | +| `Abc.example.com` | No `@` sign seperating the local and domain components. | +| `A@b@c@example.com` | Only one is allowed to divide the local and domain components. | +| `a"b(c)d,e:f;gi[j\k]l@example.com` | The local part contains invalid characters. | +| `just"not"right@example.com` | Quotes are not allowed in the local component. | +| `this is"not\allowed@example.com` | Spaces and backslashes are not allowed in the local component. | +| `this\ still\"not\\allowed@example.com` | Spaces and backslashes are not allowed in the local component. | +| `1234567890123456789012345678901234567890123456789012345678901234+x@example.com` | The local component is longer than 64 characters. | +| `i_like_underscore@but_its_not_allowed_in_this_part.example.com` | Underscores are not allowed in the domain component. | +| `QA[icon]CHOCOLATE[icon]@test.com` | Non UTF-8 characters are not allowed in the local component. | + + +# Name + +The recommended name is `EmailAddress`. Alternatives may be `Email`, `E-Mail`, `MailAddress`. + +# Result + +Every result must follow the valid String formats as described above. + +# Input + +Every input following the valid String formats as described above must be accepted. + +# References + +[RFC 5322](https://www.rfc-editor.org/rfc/rfc5322) + +[RFC 6531](https://www.rfc-editor.org/rfc/rfc6531) + +[Wikipedia](https://en.wikipedia.org/wiki/Email_address) From a92aff189c878a96deb81446ebe96cadc3ad957c Mon Sep 17 00:00:00 2001 From: Youssef Elshabasy Date: Wed, 8 Feb 2023 11:19:48 -0500 Subject: [PATCH 02/16] Grammer reformatting Co-authored-by: Ivan Maximov --- scalars/contributed/Juke-Duke/email-address.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index 0dfa9bc..2177dc9 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -27,7 +27,7 @@ The local part may contain any of the following ASCII characters: The domain part may contain any of the following ASCII characters: - Uppercase and lowercase Latin letters `A` to `Z` and `a` to `z` -- Digits `0` to `9`, provided that top-level domain names are not all-numeric (.com, .net, .org, etc.) +- Digits `0` to `9`, provided that top-level domain names are non-numeric (.com, .net, .org, etc.) - Hyphen `-`, provided that it is not the first or last character **Examples** From 71d1d32cee00a16a98de307a9e5a20aafc87c533 Mon Sep 17 00:00:00 2001 From: Youssef Elshabasy Date: Wed, 8 Feb 2023 11:20:09 -0500 Subject: [PATCH 03/16] Grammer reformatting Co-authored-by: Ivan Maximov --- scalars/contributed/Juke-Duke/email-address.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index 2177dc9..5996fbe 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -43,7 +43,7 @@ These are valid eamples: | `very.common@example.com` | An EmailAddress with a dot inside the local part. | | `disposable.style.email.with+symbol@example.com` | An EmailAddress with dots and a plus sign inside the local part. | | `other.email-with-hyphen@example.com` | An EmailAddress with a dot and hyphens inside the local part. | -| `fully-qualified-domain@example.com` | An EmailAddress with hypehns inside the local part. | +| `fully-qualified-domain@example.com` | An EmailAddress with hyphens inside the local part. | | `user.name+tag+sorting@example.com` | An EmailAddress with a dot and plus signs inside the local part | | `x@example.com` | An EmailAddress with a single character in the local part. | | `example-indeed@strange-example.com` | An EmailAddress with a hyphen in both the local and domain parts. | From 8dbbb8bfdf6c9bace8593ee1c12d81901905bb25 Mon Sep 17 00:00:00 2001 From: Youssef Elshabasy Date: Wed, 8 Feb 2023 11:21:20 -0500 Subject: [PATCH 04/16] Grammer reformatting Co-authored-by: Ivan Maximov --- scalars/contributed/Juke-Duke/email-address.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index 5996fbe..d280f4e 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -57,7 +57,7 @@ These are valid eamples: These are invalid examples: | String | Explanation | | -------------------------------------------------------------------------------- | -------------------------------------------------------------- | -| `Abc.example.com` | No `@` sign seperating the local and domain components. | +| `Abc.example.com` | No `@` sign separating the local and domain components. | | `A@b@c@example.com` | Only one is allowed to divide the local and domain components. | | `a"b(c)d,e:f;gi[j\k]l@example.com` | The local part contains invalid characters. | | `just"not"right@example.com` | Quotes are not allowed in the local component. | From 2620e470ae3f1cda828006e61840c67d77f9035e Mon Sep 17 00:00:00 2001 From: Juke-Duke Date: Wed, 8 Feb 2023 11:41:11 -0500 Subject: [PATCH 05/16] Invalid example for all numerical top level domain --- scalars/contributed/Juke-Duke/email-address.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index d280f4e..758f2c6 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -63,9 +63,10 @@ These are invalid examples: | `just"not"right@example.com` | Quotes are not allowed in the local component. | | `this is"not\allowed@example.com` | Spaces and backslashes are not allowed in the local component. | | `this\ still\"not\\allowed@example.com` | Spaces and backslashes are not allowed in the local component. | -| `1234567890123456789012345678901234567890123456789012345678901234+x@example.com` | The local component is longer than 64 characters. | +| `1234567890123456789012345678901234567890123456789012345678901234+x@example.com` | The local component is longer than 64 characters. | | `i_like_underscore@but_its_not_allowed_in_this_part.example.com` | Underscores are not allowed in the domain component. | | `QA[icon]CHOCOLATE[icon]@test.com` | Non UTF-8 characters are not allowed in the local component. | +|`all-numerical-top@levelDomain@3778.com` | Top-level domains cannot be all numerical. | # Name From 4ff17532cc61c48ed811736744c96928074decf6 Mon Sep 17 00:00:00 2001 From: Juke-Duke Date: Wed, 8 Feb 2023 11:46:52 -0500 Subject: [PATCH 06/16] Valid and Invalid example for top level domain --- scalars/contributed/Juke-Duke/email-address.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index 758f2c6..c2f582a 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -53,6 +53,7 @@ These are valid eamples: | `mailhost!username@example.org` | An EmailAddress with a bang in the local part. | | `user%example.com@example.org` | An EmailAddress with a percent sign in the local part. | | `user-@example.org` | An EmailAddress with a hyphen in the local part. | +|`non-all-numerical-top@level@domain.g2g` | An EmailAddress with a non-all-numerical top-level domain. | These are invalid examples: | String | Explanation | @@ -66,7 +67,7 @@ These are invalid examples: | `1234567890123456789012345678901234567890123456789012345678901234+x@example.com` | The local component is longer than 64 characters. | | `i_like_underscore@but_its_not_allowed_in_this_part.example.com` | Underscores are not allowed in the domain component. | | `QA[icon]CHOCOLATE[icon]@test.com` | Non UTF-8 characters are not allowed in the local component. | -|`all-numerical-top@levelDomain@3778.com` | Top-level domains cannot be all numerical. | +| `all-numerical-top@level@domain.3778` | Top-level domains cannot be all numerical. | # Name From c59a2204725d3a4c5a523577df9cb4b0dfc4561b Mon Sep 17 00:00:00 2001 From: Juke-Duke Date: Wed, 8 Feb 2023 11:55:02 -0500 Subject: [PATCH 07/16] Reformatted --- scalars/contributed/Juke-Duke/email-address.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index c2f582a..4cb1ac0 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -53,7 +53,7 @@ These are valid eamples: | `mailhost!username@example.org` | An EmailAddress with a bang in the local part. | | `user%example.com@example.org` | An EmailAddress with a percent sign in the local part. | | `user-@example.org` | An EmailAddress with a hyphen in the local part. | -|`non-all-numerical-top@level@domain.g2g` | An EmailAddress with a non-all-numerical top-level domain. | +| `non-all-numerical-top@level@domain.g2g` | An EmailAddress with a non-all-numerical top-level domain. | These are invalid examples: | String | Explanation | From 1dd80be6b3d549027597d0b9e66f67bf2f720f83 Mon Sep 17 00:00:00 2001 From: Youssef Elshabasy Date: Wed, 8 Feb 2023 12:05:40 -0500 Subject: [PATCH 08/16] Grammer reformatting Co-authored-by: Ivan Maximov --- scalars/contributed/Juke-Duke/email-address.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index 4cb1ac0..e353d59 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -67,7 +67,7 @@ These are invalid examples: | `1234567890123456789012345678901234567890123456789012345678901234+x@example.com` | The local component is longer than 64 characters. | | `i_like_underscore@but_its_not_allowed_in_this_part.example.com` | Underscores are not allowed in the domain component. | | `QA[icon]CHOCOLATE[icon]@test.com` | Non UTF-8 characters are not allowed in the local component. | -| `all-numerical-top@level@domain.3778` | Top-level domains cannot be all numerical. | +| `all-numerical-top-level@domain.3778` | Top-level domains cannot be all numerical. | # Name From a6a4c7de27976befd4ab7b56adc39f6c18c2fe28 Mon Sep 17 00:00:00 2001 From: Youssef Elshabasy Date: Wed, 8 Feb 2023 12:06:21 -0500 Subject: [PATCH 09/16] Removed double @ symbol Co-authored-by: Ivan Maximov --- scalars/contributed/Juke-Duke/email-address.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index e353d59..f969b9e 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -53,7 +53,7 @@ These are valid eamples: | `mailhost!username@example.org` | An EmailAddress with a bang in the local part. | | `user%example.com@example.org` | An EmailAddress with a percent sign in the local part. | | `user-@example.org` | An EmailAddress with a hyphen in the local part. | -| `non-all-numerical-top@level@domain.g2g` | An EmailAddress with a non-all-numerical top-level domain. | +| `non-all-numerical-top-level@domain.g2g` | An EmailAddress with a non-all-numerical top-level domain. | These are invalid examples: | String | Explanation | From e64684c54e097f71d829e9f43a4b5b8571171665 Mon Sep 17 00:00:00 2001 From: Youssef Elshabasy Date: Wed, 8 Feb 2023 12:06:42 -0500 Subject: [PATCH 10/16] Grammer reformatting Co-authored-by: Ivan Maximov --- scalars/contributed/Juke-Duke/email-address.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index f969b9e..eea1858 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -35,7 +35,7 @@ The domain part may contain any of the following ASCII characters: The general format is described in [RFC5322 Section 3.4.1](https://www.rfc-editor.org/rfc/rfc5322#section-3.4.1). These examples are taken from [WikiPedia](https://en.wikipedia.org/wiki/Email_address#Examples), which is also based off of [RFC5322 Section 3.4.1](https://www.rfc-editor.org/rfc/rfc5322#section-3.4.1). -These are valid eamples: +These are valid examples: | String | Explanation | | ------------------------------------------------ | --------------------------------------------------------------------- | From 4851bdc02898fe3815c7fd31477b12970051c214 Mon Sep 17 00:00:00 2001 From: Juke-Duke Date: Wed, 8 Feb 2023 12:14:41 -0500 Subject: [PATCH 11/16] Top level domain can not be all numeric --- scalars/contributed/Juke-Duke/email-address.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index eea1858..07af69f 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -27,7 +27,7 @@ The local part may contain any of the following ASCII characters: The domain part may contain any of the following ASCII characters: - Uppercase and lowercase Latin letters `A` to `Z` and `a` to `z` -- Digits `0` to `9`, provided that top-level domain names are non-numeric (.com, .net, .org, etc.) +- Digits `0` to `9`, provided that top-level domain names are non-all-numeric (.com, .net, .org, etc.) - Hyphen `-`, provided that it is not the first or last character **Examples** From 72ca51b73c4aa49af87882c8f2e05249ebc0110e Mon Sep 17 00:00:00 2001 From: Youssef Elshabasy Date: Wed, 8 Feb 2023 13:47:26 -0500 Subject: [PATCH 12/16] Top level domain example with number Co-authored-by: Ivan Maximov --- scalars/contributed/Juke-Duke/email-address.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index 07af69f..cf80436 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -27,7 +27,7 @@ The local part may contain any of the following ASCII characters: The domain part may contain any of the following ASCII characters: - Uppercase and lowercase Latin letters `A` to `Z` and `a` to `z` -- Digits `0` to `9`, provided that top-level domain names are non-all-numeric (.com, .net, .org, etc.) +- Digits `0` to `9`, provided that top-level domain names are non-all-numeric (.com, .net, .org, b2b, etc.) - Hyphen `-`, provided that it is not the first or last character **Examples** From 09eca20a75b0f0f21f434158320190fd59790a90 Mon Sep 17 00:00:00 2001 From: Youssef Elshabasy Date: Wed, 8 Feb 2023 15:36:49 -0500 Subject: [PATCH 13/16] Added missing . to b2b top level domain example Co-authored-by: Ivan Maximov --- scalars/contributed/Juke-Duke/email-address.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index cf80436..3fb5721 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -27,7 +27,7 @@ The local part may contain any of the following ASCII characters: The domain part may contain any of the following ASCII characters: - Uppercase and lowercase Latin letters `A` to `Z` and `a` to `z` -- Digits `0` to `9`, provided that top-level domain names are non-all-numeric (.com, .net, .org, b2b, etc.) +- Digits `0` to `9`, provided that top-level domain names are non-all-numeric (.com, .net, .org, .b2b, etc.) - Hyphen `-`, provided that it is not the first or last character **Examples** From e1947bfd15adee522a1071ecbb2a3825490b7bc9 Mon Sep 17 00:00:00 2001 From: Juke-Duke Date: Wed, 8 Feb 2023 18:07:33 -0500 Subject: [PATCH 14/16] Reformatted --- scalars/contributed/Juke-Duke/email-address.md | 1 - 1 file changed, 1 deletion(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index 3fb5721..130a5d3 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -69,7 +69,6 @@ These are invalid examples: | `QA[icon]CHOCOLATE[icon]@test.com` | Non UTF-8 characters are not allowed in the local component. | | `all-numerical-top-level@domain.3778` | Top-level domains cannot be all numerical. | - # Name The recommended name is `EmailAddress`. Alternatives may be `Email`, `E-Mail`, `MailAddress`. From 49363814776b30a887566f9ab8dcd07fcd01a0a0 Mon Sep 17 00:00:00 2001 From: Juke-Duke Date: Wed, 8 Feb 2023 18:16:47 -0500 Subject: [PATCH 15/16] Provided regex that may be used for validation --- scalars/contributed/Juke-Duke/email-address.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index 130a5d3..a5b7f78 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -69,6 +69,11 @@ These are invalid examples: | `QA[icon]CHOCOLATE[icon]@test.com` | Non UTF-8 characters are not allowed in the local component. | | `all-numerical-top-level@domain.3778` | Top-level domains cannot be all numerical. | +This regex provided below follows the above examples: +```regex +^(?!\.)(?!.*\.\.)[a-zA-Z0-9!#$%&'*+-/=?^_`{|}~\.]{0,63}[^\.]@(?!\-)[a-zA-Z0-9-]+[^\-]\.?(?!\d+$)[a-zA-Z0-9]{2,255}$ +``` + # Name The recommended name is `EmailAddress`. Alternatives may be `Email`, `E-Mail`, `MailAddress`. From 95c694043e8f083171754214b757c866c0c8a913 Mon Sep 17 00:00:00 2001 From: Juke-Duke Date: Tue, 21 Feb 2023 22:38:30 -0500 Subject: [PATCH 16/16] Refactored domain part and regex with explanation --- .../contributed/Juke-Duke/email-address.md | 98 +++++++++++-------- 1 file changed, 58 insertions(+), 40 deletions(-) diff --git a/scalars/contributed/Juke-Duke/email-address.md b/scalars/contributed/Juke-Duke/email-address.md index a5b7f78..c92b975 100644 --- a/scalars/contributed/Juke-Duke/email-address.md +++ b/scalars/contributed/Juke-Duke/email-address.md @@ -15,20 +15,20 @@ Copyright © GraphQL contributors. This specification is licensed under This Scalar represents a valid electronic mail address using a simplified version of [RFC 5322](https://www.rfc-editor.org/rfc/rfc5322). -The format of an email address is `local@domain`, where the local part may consist of up to 64 UTF-8 characters, the domain part may consist of up to 255 UTF-8 characters, and the two parts are separated by an `@` sign. +The format of an email address is `local@domain`, where the local part may consist of up to 64 UTF-8 characters, the domain part may consist of up to 63 UTF-8 characters for the domain name and 63 UTF-8 characters for the top-level domain, and the two parts are separated by an `@` sign. Other formats, including using square-bracketed IP addresses in the domain part, and quoted-string local parts, are not supported for simplicity. -The local part may contain any of the following ASCII characters: -- Uppercase and lowercase Latin letters `A` to `Z` and `a` to `z` -- Digits `0` to `9` -- Printable characters ``!#$%&'*+-/=?^_`{|}~`` -- Dot `.`, provided that it is not the first or last character and provided also that it does not appear consecutively +The local component may contain any of the following ASCII characters: +- Uppercase and lowercase Latin letters `A` to `Z` and `a` to `z`. +- Digits `0` to `9`. +- Printable characters ``!#$%&'*+-/=?^_`{|}~``. +- Dot `.`, provided that it is not the first or last character and provided also that it does not appear consecutively. -The domain part may contain any of the following ASCII characters: -- Uppercase and lowercase Latin letters `A` to `Z` and `a` to `z` -- Digits `0` to `9`, provided that top-level domain names are non-all-numeric (.com, .net, .org, .b2b, etc.) -- Hyphen `-`, provided that it is not the first or last character +The domain component may contain any of the following ASCII characters: +- Uppercase and lowercase Latin letters `A` to `Z` and `a` to `z`. +- Digits `0` to `9`, provided that top-level domain names are non-all-numeric (.com, .net, .org, .b2b, etc.). +- Hyphen `-`, provided that it is not the first or last character of the domain name. **Examples** @@ -37,43 +37,61 @@ These examples are taken from [WikiPedia](https://en.wikipedia.org/wiki/Email_ad These are valid examples: -| String | Explanation | -| ------------------------------------------------ | --------------------------------------------------------------------- | -| `simple@example.com` | An EmailAddress without any special characters. | -| `very.common@example.com` | An EmailAddress with a dot inside the local part. | -| `disposable.style.email.with+symbol@example.com` | An EmailAddress with dots and a plus sign inside the local part. | -| `other.email-with-hyphen@example.com` | An EmailAddress with a dot and hyphens inside the local part. | -| `fully-qualified-domain@example.com` | An EmailAddress with hyphens inside the local part. | -| `user.name+tag+sorting@example.com` | An EmailAddress with a dot and plus signs inside the local part | -| `x@example.com` | An EmailAddress with a single character in the local part. | -| `example-indeed@strange-example.com` | An EmailAddress with a hyphen in both the local and domain parts. | -| `test/test@test.com` | An EmailAddress with a slash in the local part. | -| `admin@mailserver1` | An EmailAddress with no top-level domain. This is highly discouraged. | -| `example@s.example` | An EmailAddress with a dot in the domain part. | -| `mailhost!username@example.org` | An EmailAddress with a bang in the local part. | -| `user%example.com@example.org` | An EmailAddress with a percent sign in the local part. | -| `user-@example.org` | An EmailAddress with a hyphen in the local part. | -| `non-all-numerical-top-level@domain.g2g` | An EmailAddress with a non-all-numerical top-level domain. | +| String | Explanation | +| ------------------------------------------------ | ----------------------------------------------------------------- | +| `simple@example.com` | An EmailAddress without any special characters. | +| `very.common@example.com` | An EmailAddress with a dot inside the local part. | +| `disposable.style.email.with+symbol@example.com` | An EmailAddress with dots and a plus sign inside the local part. | +| `other.email-with-hyphen@example.com` | An EmailAddress with a dot and hyphens inside the local part. | +| `fully-qualified-domain@example.com` | An EmailAddress with hyphens inside the local part. | +| `user.name+tag+sorting@example.com` | An EmailAddress with a dot and plus signs inside the local part | +| `x@example.com` | An EmailAddress with a single character in the local part. | +| `example-indeed@strange-example.com` | An EmailAddress with a hyphen in both the local and domain parts. | +| `test/test@test.com` | An EmailAddress with a slash in the local part. | +| `example@s.example` | An EmailAddress with a dot in the domain part. | +| `mailhost!username@example.org` | An EmailAddress with a bang in the local part. | +| `user%example.com@example.org` | An EmailAddress with a percent sign in the local part. | +| `user-@example.org` | An EmailAddress with a hyphen in the local part. | +| `non-all-numerical-top-level@domain.g2g` | An EmailAddress with a non-all-numerical top-level domain. | These are invalid examples: -| String | Explanation | -| -------------------------------------------------------------------------------- | -------------------------------------------------------------- | -| `Abc.example.com` | No `@` sign separating the local and domain components. | -| `A@b@c@example.com` | Only one is allowed to divide the local and domain components. | -| `a"b(c)d,e:f;gi[j\k]l@example.com` | The local part contains invalid characters. | -| `just"not"right@example.com` | Quotes are not allowed in the local component. | -| `this is"not\allowed@example.com` | Spaces and backslashes are not allowed in the local component. | -| `this\ still\"not\\allowed@example.com` | Spaces and backslashes are not allowed in the local component. | -| `1234567890123456789012345678901234567890123456789012345678901234+x@example.com` | The local component is longer than 64 characters. | -| `i_like_underscore@but_its_not_allowed_in_this_part.example.com` | Underscores are not allowed in the domain component. | -| `QA[icon]CHOCOLATE[icon]@test.com` | Non UTF-8 characters are not allowed in the local component. | -| `all-numerical-top-level@domain.3778` | Top-level domains cannot be all numerical. | +| String | Explanation | +| -------------------------------------------------------------------------------- | ----------------------------------------------------------------- | +| `Abc.example.com` | No `@` sign separating the local and domain components. | +| `A@b@c@example.com` | Only one is allowed to divide the local and domain components. | +| `a"b(c)d,e:f;gi[j\k]l@example.com` | The local part contains invalid characters. | +| `just"not"right@example.com` | Quotes are not allowed in the local component. | +| `this is"not\allowed@example.com` | Spaces and backslashes are not allowed in the local component. | +| `this\ still\"not\\allowed@example.com` | Spaces and backslashes are not allowed in the local component. | +| `1234567890123456789012345678901234567890123456789012345678901234+x@example.com` | The local component is longer than 64 characters. | +| `i_like_underscore@but_its_not_allowed_in_this_part.example.com` | Underscores are not allowed in the domain component. | +| `QA[icon]CHOCOLATE[icon]@test.com` | Non UTF-8 characters are not allowed in the local component. | +| `all-numerical-top-level@domain.3778` | Top-level domains cannot be all numerical. | +| `admin@mailserver1` | The top-level domain component is missing. | +| `hyphens-in-domain@-domain-.com` | The domain component can not have hyphes in the beginning or end. | This regex provided below follows the above examples: ```regex -^(?!\.)(?!.*\.\.)[a-zA-Z0-9!#$%&'*+-/=?^_`{|}~\.]{0,63}[^\.]@(?!\-)[a-zA-Z0-9-]+[^\-]\.?(?!\d+$)[a-zA-Z0-9]{2,255}$ +^(?!\.)(?!.*\.\.)[a-zA-Z0-9!#$%&'*+-/=?^_`{|}~\.]{0,63}[^.]@(?!\-)[a-zA-Z0-9-]{0,62}[^-]\.(?![0-9]*$)[a-zA-Z0-9]{2,63}$ ``` +Regex Breakdown: +- `^` Beginning of the string. +- `(?!\.)(?!.*\.\.)` Look aheads that assert the local component does not start and contain consecutive dots. +- `[a-zA-Z0-9!#$%&'*+-/=?^_`{|}~\.]` Asserts the local component may contain any of these characters. +- `{0,63}` Asserts the length of the local component is between 1 and 64 characters inclusive. +- `[^.]` Asserts that the local component does not end with a dot. +- `@` Asserts that the local component is followed by an `@` sign. +- `(?!\-)(?!.*\-\-)` Look aheads that assert the domain component name does not start or contain consecutive hyphens. +- `[a-zA-Z0-9-]` Asserts the domain component name may contain any of these characters. +- `{0,62}` Asserts the length of the domain component name is between 1 and 63 characters inclusive. +- `[^-]` Asserts that the domain component name does not end with a hyphen. +- `\.` Asserts that the domain component name is followed by a dot. +- `(?![0-9]*$)` Look ahead that asserts the top-level domain does not only contain numbers. +- `[a-zA-Z0-9]` Asserts the top-level domain may contain any of these characters. +- `{2,63}` Asserts the length of the top-level domain is between 2 and 63 characters inclusive. +- `$` End of the string. + # Name The recommended name is `EmailAddress`. Alternatives may be `Email`, `E-Mail`, `MailAddress`.