我想为所有电子邮件地址(包括非斜体字符)编写正则表达式。
我试过了,但是返回假
请尽快提供正确的解决方案
<!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 help me to correct it
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>
虽然有更好的方法来确保您的电子邮件正则表达式有效(请参阅@Tushar的注释),但我想解释一下您的正则表达式存在什么问题。
所述^([\\p{L}+|\\p{N}*][@][\\p{L}+][.][\\p{L}+])$
包含不正确地形成字符类[\\p{L}+|\\p{N}*]
和[\\p{L}+]
。它们匹配在他们里面定义的单个字符-[\\p{L}+|\\p{N}*]
比赛或者是p
,{
,L
等,[\\p{L}+]
火柴或者是p
,{
,L
,}
,或+
。
如果您打算使用此方法,则可能需要将正则表达式修复为
XRegExp('^[\\p{L}\\p{N}]+@\\p{L}+[.]\\p{L}+$')
详细资料:
^
-字符串开始[\\p{L}\\p{N}]+
-一个或多个Unicode字母或数字@
-“在”标志\\p{L}+
-一个或多个Unicode字母[.]
-文字点\\p{L}+
-同上$
-字符串结尾。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句