Jquery验证Email邮箱格式的代码一例
本文导语: 代码如下: 代码示例: Jqury验证邮箱代码示例_www. //验证邮箱,正确返回true,错误返回false function checkEmail(email){ var emailRegExp = new RegExp( "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[...
代码如下:
Jqury验证邮箱代码示例_www.
//验证邮箱,正确返回true,错误返回false
function checkEmail(email){
var emailRegExp = new RegExp( "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");
if (!emailRegExp.test(email)||email.indexOf('.')==-1){
return false;
}else{
return true;
}
}
//验证输入框内信息,并给出对应提示
function test(obj){
if(obj=="mail"){
var email=$.trim($("input[name='mail']").val());
if(email==""){
$("#tishi_mail").html("
登陆邮箱不能为空!
");$("#tishi_mail p").addClass("tsTxt_error");
}else{
if(!checkEmail(email)){
$("#tishi_mail").html("
请输入常用邮箱!
");$("#tishi_mail p").addClass("tsTxt_error");
}else{
$("#tishi_mail").html("
你输入的邮箱格式正确
");$("#tishi_mail p").addClass("tsTxt");
};
}
}
};
body{color:#fff;font-weight:bold;background:#333}
.tsTxt_error{width:200px;height:20px;line-height:20px;color:#F00;padding:0 10px;}
.tsTxt{width:200px;height:20px;line-height:20px;color:#0C0;padding:0 10px;}
输入邮箱地址,点击框外显示测试结果。
您可能感兴趣的文章:
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。