Hi,
We have followed the regex for validating RFC 2822 standard.
The function is as follows:
int isValidEmail(const char *email_id)
{
/* Regular expression to validate email */
const char *reg_exp =
"[a-z0-9!#$%&'*+-/=?^_`{|}~]+(\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@([a-z0-9]([a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?$";
regex_t preg;
/* Compile the regular expression */
if (regcomp(&preg, reg_exp, REG_EXTENDED|REG_NOSUB|REG_ICASE) != 0)
return FAILURE;
/* Execute the regex, 0 for success */
if (regexec(&preg, email_id, (size_t)0, NULL, 0) != 0)
return FAILURE;
regfree(&preg);
return SUCCESS;
}
But if I provide emails like "test@[email protected]", the emails are getting accepted.
Is there any problem with this regex?
Appreciate the help in advance.
Thanks, Mathew Liju