Chore: Centralize email validation functionality (#23816)
parent
2d6aa92851
commit
7159bfffcb
@ -0,0 +1,12 @@ |
||||
export const validateEmail = (email: string, options: { style: string } = { style: 'basic' }): boolean => { |
||||
const basicEmailRegex = /^[^@]+@[^@]+$/; |
||||
const rfcEmailRegex = /^[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])?)*$/; |
||||
|
||||
switch (options.style) { |
||||
case 'rfc': |
||||
return rfcEmailRegex.test(email); |
||||
case 'basic': |
||||
default: |
||||
return basicEmailRegex.test(email); |
||||
} |
||||
}; |
Loading…
Reference in new issue