kailash Chandra kailash Chandra - 1 year ago 105
Javascript Question

XRegExp for email address

I want to write regular expression for email address for all including non-italic characters.

I tried but it return false

Please provide correct solution as soon as possible

<!DOCTYPE html>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/xregexp/3.1.1/xregexp-all.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript">
var em = XRegExp('^([\\p{L}+|\\p{N}*][@][\\p{L}+][.][\\p{L}+])$'); // Please help me to correct it


Enter Name: <input type="text" name="t1" id="t1" class="kcd">

Answer Source

While there are better means to make sure your email regex is valid (see @Tushar's comment), I'd like to explain what the problem is with your regex.

The ^([\\p{L}+|\\p{N}*][@][\\p{L}+][.][\\p{L}+])$ contains incorrectly formed character classes [\\p{L}+|\\p{N}*] and [\\p{L}+]. They match a single character defined inside them - [\\p{L}+|\\p{N}*] matches either a p, {, L, etc. and [\\p{L}+] matches either a p, {, L, }, or +.

If you plan to use your approach, you might want to fix the regex as



  • ^ - start of string
  • [\\p{L}\\p{N}]+ - one or more Unicode letters or digits
  • @ - "at" sign
  • \\p{L}+ - one or more Unicode letters
  • [.] - a literal dot
  • \\p{L}+ - ibid.
  • $ - end of string.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download