-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
Chore: Centralize email validation functionality #23816
Chore: Centralize email validation functionality #23816
Conversation
lib/emailValidator.ts
Outdated
case 'basic': | ||
return basicEmailRegex.test(email); | ||
case 'rfc': | ||
return rfcEmailRegex.test(email); | ||
default: | ||
return basicEmailRegex.test(email); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
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 🤔
lib/emailValidator.ts
Outdated
@@ -0,0 +1,13 @@ | |||
export const validateEmail = (email: string, options: { style: string } = { style: 'basic' }): boolean => { | |||
const basicEmailRegex = /^.+@.+$/; |
There was a problem hiding this comment.
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? 👀
There was a problem hiding this comment.
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 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, this one 😬 ^[^@]+@[^@]+$
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I have approved it already, what about writing some unit tests for it? maybe we can have an agreement that all functions in |
Proposed changes (including videos or screenshots)
Issue(s)
Steps to test or reproduce
Further comments