Skip to content

Chore: Centralize email validation functionality#23816

Merged
sampaiodiego merged 3 commits intodevelopfrom
chore/centralize-email-validation-regexes
Dec 20, 2021
Merged

Chore: Centralize email validation functionality#23816
sampaiodiego merged 3 commits intodevelopfrom
chore/centralize-email-validation-regexes

Conversation

@KevLehman
Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

  • Create lib for validating emails
  • Modify places that validate emails to use the new central function

Issue(s)

Steps to test or reproduce

Further comments

Comment on lines +6 to +11
case 'basic':
return basicEmailRegex.test(email);
case 'rfc':
return rfcEmailRegex.test(email);
default:
return basicEmailRegex.test(email);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
case 'basic':
return basicEmailRegex.test(email);
case 'rfc':
return rfcEmailRegex.test(email);
default:
return basicEmailRegex.test(email);
case 'rfc':
return rfcEmailRegex.test(email);
case 'basic':
default:
return basicEmailRegex.test(email);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought we had the no-fallthrough rule enabled 🤔

@@ -0,0 +1,13 @@
export const validateEmail = (email: string, options: { style: string } = { style: 'basic' }): boolean => {
const basicEmailRegex = /^.+@.+$/;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looking into some regex you modified to use this function I found this one interesting: [^@].*@[^@], it makes sure only a single @ is allowed.. wdyt? 👀

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fair enough, let me do the change 👀

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

image
Not sure 🙈 if we should use it tho

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oopsie.. looks like I missread the regex 🙈

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok, this one 😬 ^[^@]+@[^@]+$

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That works way better 👀
image

@sampaiodiego
Copy link
Copy Markdown
Member

Although I have approved it already, what about writing some unit tests for it? maybe we can have an agreement that all functions in /lib should have unit tests.. wdyt?

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Dec 17, 2021

CLA assistant check
All committers have signed the CLA.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants