i want write regular expression email address including non-italic characters.
i tried return false
please provide correct solution possible
<!doctype html> <html> <head> <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 me correct jquery(function(){ jquery('input').blur(function(){ console.log(jquery(this).val()); console.log(em.test(jquery('#t1').val())); }); }); </script> <title></title> </head> <body> enter name: <input type="text" name="t1" id="t1" class="kcd"> </body> </html>
while there better means make sure email regex valid (see @tushar's comment), i'd explain problem regex.
the ^([\\p{l}+|\\p{n}*][@][\\p{l}+][.][\\p{l}+])$ contains incorrectly formed character classes [\\p{l}+|\\p{n}*] , [\\p{l}+]. match single character defined inside them - [\\p{l}+|\\p{n}*] matches either p, {, l, etc. , [\\p{l}+] matches either p, {, l, }, or +.
if plan use approach, might want fix regex as
xregexp('^[\\p{l}\\p{n}]+@\\p{l}+[.]\\p{l}+$') details:
^- start of string[\\p{l}\\p{n}]+- 1 or more unicode letters or digits@- "at" sign\\p{l}+- 1 or more unicode letters[.]- literal dot\\p{l}+- ibid.$- end of string.
Comments
Post a Comment