From 61bf867d99f533e61ef0d6e5edd9e09e15beebd3 Mon Sep 17 00:00:00 2001 From: Ian Emsens Date: Wed, 19 Mar 2025 17:31:24 +0100 Subject: [PATCH 1/4] chore: fix typo --- .../be-phone-bin-formatted/be-phone-bin-formatted.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/javascript/regex/src/lib/patterns/regional/be-phone-bin-formatted/be-phone-bin-formatted.spec.ts b/libs/javascript/regex/src/lib/patterns/regional/be-phone-bin-formatted/be-phone-bin-formatted.spec.ts index f864c8f3..7d07eb0b 100644 --- a/libs/javascript/regex/src/lib/patterns/regional/be-phone-bin-formatted/be-phone-bin-formatted.spec.ts +++ b/libs/javascript/regex/src/lib/patterns/regional/be-phone-bin-formatted/be-phone-bin-formatted.spec.ts @@ -13,7 +13,7 @@ describe('phoneBelgiumBinFormatted', () => { expect(bePhoneBinFormatted.mobilePattern.test('0470 12 34 56')).toBe(true); }); - it('should not test true to non-BIN formatted mobile phone numbers;', () => { + it('should not test true to non-BIN formatted mobile phone numbers', () => { expect(bePhoneBinFormatted.mobilePattern.test('003212345678')).toBe(false); expect(bePhoneBinFormatted.mobilePattern.test('+3212345678')).toBe(false); expect(bePhoneBinFormatted.mobilePattern.test('012345678')).toBe(false); From 8595e84f5f8588e470a8116033dc12fba3b331d7 Mon Sep 17 00:00:00 2001 From: Ian Emsens Date: Wed, 19 Mar 2025 17:33:35 +0100 Subject: [PATCH 2/4] feat: add html spec email regex --- .../patterns/technical/email/email.spec.ts | 45 +++++++++++++++++++ .../src/lib/patterns/technical/email/email.ts | 8 ++++ .../regex/src/lib/patterns/technical/index.ts | 1 + 3 files changed, 54 insertions(+) create mode 100644 libs/javascript/regex/src/lib/patterns/technical/email/email.spec.ts create mode 100644 libs/javascript/regex/src/lib/patterns/technical/email/email.ts create mode 100644 libs/javascript/regex/src/lib/patterns/technical/index.ts diff --git a/libs/javascript/regex/src/lib/patterns/technical/email/email.spec.ts b/libs/javascript/regex/src/lib/patterns/technical/email/email.spec.ts new file mode 100644 index 00000000..f4b90e03 --- /dev/null +++ b/libs/javascript/regex/src/lib/patterns/technical/email/email.spec.ts @@ -0,0 +1,45 @@ +import { describe } from 'vitest'; + +import { emailPattern } from './email'; + +describe('phoneBelgiumBinFormatted', () => { + it('should test true to email addresses that comply', () => { + // https://en.wikipedia.org/wiki/Email_address#Valid_email_addresses + [ + 'simple@example.com', + 'very.common@example.com', + 'FirstName.LastName@EasierReading.org', + 'x@example.com', + 'long.email-address-with-hyphens@and.subdomains.example.com', + 'user.name+tag+sorting@example.com', + 'user.name@example.com', + 'name/surname@example.com', + 'admin@example', + 'example@s.example', + '" "@example.org', + '"john..doe"@example.org', + 'mailhost!username@example.org', + '"very.(),:;<>[]\\".VERY.\\"very@\\\\ \\"very\\".unusual"@strange.example.com', + 'user%example.com@example.org', + 'user-@example.org', + 'postmaster@[123.123.123.123]', + 'postmaster@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0370:7334]', + '_test@[IPv6:2001:0db8:85a3:0000:0000:8a2e:0370:7334]', + 'I❤️CHOCOLATE@example.com', + ].forEach((value) => expect(emailPattern.test(value)).toBe(true)); + }); + + it('should not test true to email addresses that do not comply', () => { + // https://en.wikipedia.org/wiki/Email_address#Invalid_email_addresses + [ + 'abc.example.com', + 'a@b@c@example.com', + 'a"b(c)d,e:f;gi[j\\k]l@example.com', + 'just"not"right@example.com', + 'this is"not\\allowed@example.com', + 'this\\ still\\"not\\\\allowed@example.com', + '1234567890123456789012345678901234567890123456789012345678901234+x@example.com', + 'i.like.underscores@but_they_are_not_allowed_in_this_part', + ].forEach((value) => expect(emailPattern.test(value)).toBe(false)); + }); +}); diff --git a/libs/javascript/regex/src/lib/patterns/technical/email/email.ts b/libs/javascript/regex/src/lib/patterns/technical/email/email.ts new file mode 100644 index 00000000..cbd64a16 --- /dev/null +++ b/libs/javascript/regex/src/lib/patterns/technical/email/email.ts @@ -0,0 +1,8 @@ +/* eslint-disable no-useless-escape */ + +/** + * The html-spec email regex pattern. + * https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address + */ +export const emailPattern = + /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/; diff --git a/libs/javascript/regex/src/lib/patterns/technical/index.ts b/libs/javascript/regex/src/lib/patterns/technical/index.ts new file mode 100644 index 00000000..d28e5c37 --- /dev/null +++ b/libs/javascript/regex/src/lib/patterns/technical/index.ts @@ -0,0 +1 @@ +export * from './email/email'; From b01e807d62b5a9e099c6f8b5112f1b0cf052ab5d Mon Sep 17 00:00:00 2001 From: Ian Emsens Date: Wed, 19 Mar 2025 17:38:49 +0100 Subject: [PATCH 3/4] feat: add email regex docs --- .../javascript/regex/expressions/email/index.md | 17 +++++++++++++++++ .../regex/expressions/email/ng-doc.page.ts | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 apps/docs/src/app/pages/docs/javascript/regex/expressions/email/index.md create mode 100644 apps/docs/src/app/pages/docs/javascript/regex/expressions/email/ng-doc.page.ts diff --git a/apps/docs/src/app/pages/docs/javascript/regex/expressions/email/index.md b/apps/docs/src/app/pages/docs/javascript/regex/expressions/email/index.md new file mode 100644 index 00000000..2dea1521 --- /dev/null +++ b/apps/docs/src/app/pages/docs/javascript/regex/expressions/email/index.md @@ -0,0 +1,17 @@ +--- +keyword: email +--- + +The email pattern is sourced from the [HTML spec](https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address). + +``` +/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ +``` + +## How to use + +```typescript +import { emailPattern } from '@studiohyperdrive/regex-common'; + +const isValidEmail = emailPattern.test('simple@example.com'); +``` diff --git a/apps/docs/src/app/pages/docs/javascript/regex/expressions/email/ng-doc.page.ts b/apps/docs/src/app/pages/docs/javascript/regex/expressions/email/ng-doc.page.ts new file mode 100644 index 00000000..2e19ddc0 --- /dev/null +++ b/apps/docs/src/app/pages/docs/javascript/regex/expressions/email/ng-doc.page.ts @@ -0,0 +1,11 @@ +import { NgDocPage } from '@ng-doc/core'; +import { ExpressionsCategory } from '../../../../../../categories/javascript'; + +const emailPage: NgDocPage = { + title: `email`, + mdFile: './index.md', + category: ExpressionsCategory, + order: 1, +}; + +export default emailPage; From 30f2a1f19c543d42d2b4d544822fe9b268d0c7a8 Mon Sep 17 00:00:00 2001 From: Ian Emsens Date: Thu, 20 Mar 2025 09:06:36 +0100 Subject: [PATCH 4/4] chore: fix typo --- .../regex/src/lib/patterns/technical/email/email.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/javascript/regex/src/lib/patterns/technical/email/email.spec.ts b/libs/javascript/regex/src/lib/patterns/technical/email/email.spec.ts index f4b90e03..2d315494 100644 --- a/libs/javascript/regex/src/lib/patterns/technical/email/email.spec.ts +++ b/libs/javascript/regex/src/lib/patterns/technical/email/email.spec.ts @@ -2,7 +2,7 @@ import { describe } from 'vitest'; import { emailPattern } from './email'; -describe('phoneBelgiumBinFormatted', () => { +describe('emailPattern', () => { it('should test true to email addresses that comply', () => { // https://en.wikipedia.org/wiki/Email_address#Valid_email_addresses [