手机号码认证:
(!/^((13\d{9})|(15[0-3,5-9]\d{8})|(14[5,7]\d{8})|(18[0,2-9]\d{8}))$/.test(this.value))
例子:
//手机号认证 $("#phonenum").blur(function(){ if(this.value==""||this.value.length!=11||(!/^((13\d{9})|(15[0-3,5-9]\d{8})|(14[5,7]\d{8})|(18[0,2-9]\d{8}))$/.test(this.value))){ $(this).parent().parent().addClass("error"); $(this).parent().siblings(".form_tip").html("手机号格式不正确"); $(this).css("border","1px solid #900"); }else{ $(this).parent().parent().addClass("succeed"); $(this).parent().siblings(".form_tip").html("输入正确"); $(this).css("border","1px solid #090"); } }).focus(function(){ $(this).parent().siblings(".replace_value").html(""); $(this).parent().siblings(".form_tip").html(""); $(this).parent().parent().removeClass("error"); $(this).parent().parent().removeClass("succeed"); $(this).css("border","1px solid #999"); })
邮箱格式认证:
""&&!/.+@.+\.[a-zA-Z]{2,4}$/.test(this.value)
例子:
//邮箱认证 $("#email").blur(function(){ if(this.value==""||this.value!=""&&!/.+@.+\.[a-zA-Z]{2,4}$/.test(this.value)){ $(this).parent().parent().addClass("error"); $(this).parent().siblings(".form_tip").html("邮箱格式不正确"); $(this).css("border","1px solid #900"); }else{ $(this).parent().parent().addClass("succeed"); $(this).parent().siblings(".form_tip").html("输入正确"); $(this).css("border","1px solid #090"); } }).focus(function(){ $(this).parent().siblings(".replace_value").html(""); $(this).parent().siblings(".form_tip").html(""); $(this).parent().parent().removeClass("error"); $(this).parent().parent().removeClass("succeed"); $(this).css("border","1px solid #999"); });