1

I need to make email validation on client side same with FILTER_VALIDATE_EMAIL. So what would be the equivalent regex on javascript with the FILTER_VALIDATE_EMAIL?

I found that FILTER_VALIDATE_EMAIL regex is from here: http://squiloople.com/2009/12/20/email-address-validation/ but when I tried to copy paste the regex to javascript I get SyntaxError: Invalid regular expression: /#<error>/: Invalid group

biox
  • 1,526
  • 5
  • 17
  • 28
  • http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address – adeneo Jul 06 '14 at 04:26
  • 1
    @SolracRagnarockradio yes but is it the same with FILTER_VALIDATE_EMAIL? I don't want the email to pass one validation and fail on another. – biox Jul 06 '14 at 04:35
  • 2
    That forum entry you link is from 2009 and never claims to show the validation used by PHP. Actual expression can be found at [logical_filters.c](https://github.com/php/php-src/blob/master/ext/filter/logical_filters.c#L503). – Álvaro González Jul 06 '14 at 07:23
  • [mpyw/FILTER_VALIDATE_EMAIL.js: JavaScript Email validation compatible with PHP's filter_var($value, FILTER_VALIDATE_EMAIL)](https://github.com/mpyw/FILTER_VALIDATE_EMAIL.js) – mpyw Jul 22 '18 at 12:22

1 Answers1

0

I was unable to edit my previous comment. Of course we wont validate DNS resolution, MTA precense or IP, but you can check a "string" with this one and it does a pretty good job:

/^[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])?)*$/

This is the reference: http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#e-mail-state-%28type=email%29

Solrac
  • 924
  • 8
  • 23