deep-email-validator icon indicating copy to clipboard operation
deep-email-validator copied to clipboard

Real Regex for the regex option

Open yovanoc opened this issue 5 years ago • 2 comments

const emailReg = new RegExp(
  /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
);
/**
 * Validate email function with regular expression
 *
 * If email isn't valid then return false
 *
 * @param email
 * @return Boolean
 */
export const validateEmail = (email: string): boolean => emailReg.test(email);

I use this function in several projects. I think it's more robust than the regex option here, but I need all your other options, so what do you think?

thanks

yovanoc avatar Dec 16 '20 15:12 yovanoc

Hey I've intentionally avoided regex as it can produce false negatives. It would be easy enough to add an extra option - something like validateStrictRegex: true. I would welcome a PR. Oh and happy birthday 🎂

mfbx9da4 avatar Dec 21 '20 13:12 mfbx9da4

Thanks for my birthday, I will try to open a PR soon

yovanoc avatar Dec 21 '20 13:12 yovanoc