其他教程

其他教程

Products

当前位置:首页 > 其他教程 >

ajax中如何加入正则表达式

GG网络技术分享 2025-03-18 16:14 10


问题描述:

我写的验证方法要不只能验证邮箱存在不存在,要不验证输入是否为空!不能验证邮箱格式是否正确

验证邮箱的正则表达式是 /\\w+@\\w+.\\w/

我的代码是

 <script type=\"text/javascript\">

$().ready(function (){

$(\"#zhanghao1\").blur(function(){

$(\"#infor\").empty();

var userName=$(\"#zhanghao1\").val();

if(userName.length==0){

$(\"#infor\").append(\"<h2>账号不能为空</h2>\");

}else{

$.post(\"checkUserName.do\",{userName : userName},function(data){

$(\"#infor\").append(\"<h2>\"+data+\"</h2>\");

});

}

});

});

</script>

账号:<input type=\"text\" id=\"zhanghao1\" name=\"userName\"><div id=\"infor\"></div>

网友观点:

         $(\\\"#zhanghao1\\\").blur(function () {

$(\\\"#infor\\\").empty();

var userName = $(\\\"#zhanghao1\\\").val();

if (/^\\w+@\\w+.\\w$/.test(userName)) {

$(\\\"#infor\\\").append(\\\"<h2>账号不正确</h2>\\\");

} else {

$.post(\\\"checkUserName.do\\\", { userName: userName }, function (data) {

$(\\\"#infor\\\").append(\\\"<h2>\\\" + data + \\\"</h2>\\\");

});

}

});

javascript 正则表达式(笔记)

介绍一个正则表达式图形化工具,当你无法抽象理解所看到的正则表达式时,这个工具十分有用。

  • 正则表达式中的特殊字符
  • 使用正则表达式


正则表达式中的特殊字符

标签:

提交需求或反馈

Demand feedback