js 常用验证
邮箱验证:
$(function ()
{
$("#txt_Email").blur(function ()
{
var email =
/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
var str =
$("#txt_Email").val();
if (email.test(str) == false)
{
alert(‘对不起,请输入正确的邮箱!‘);
return;
}
});
});
各种证件号验证:
$("#txt_IdCard").blur(function ()
{
var officer =
/\d{8}/;
var Idcard =
/(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$)|(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)/;
var huzhao =
/^(P\d{7}|G\d{8}|S\d{7,8}|D\d+|1[4,5]\d{7})$/;
var taibaozheng =
/^[a-zA-Z]([0-9]\d{9})$/;
var gangaotongxingzheng =
/\d{9}/;
var str =
$("#txt_IdCard").val();
if ($("#drop_Card").val() == "身份证")
{
var r =
str.match(Idcard);
if (Idcard.test(str) == false)
{
alert(‘对不起,您输入的身份证证件号不正确!‘);
return;
}
var birthday = $(this).val().substr(6, 4) + "-" + $(this).val().substr(10, 2) +
"-" + $(this).val().substr(12,
2);
$("#txt_Birth").val(birthday);
}
else if ($("#drop_Card").val() == "军官证")
{
if (officer.test(str) == false)
{
alert(‘对不起,您输入的军官证证件号不正确!‘);
return;
}
}
else if ($("#drop_Card").val() == "港澳通行证")
{
if (gangaotongxingzheng.test(str) == false)
{
alert(‘对不起,您输入的港澳通行证证件号不正确!‘);
return;
}
}
else if ($("#drop_Card").val() == "台胞证")
{
if (taibaozheng.test(str) == false)
{
alert(‘对不起,您输入的台胞证证件号不正确!‘);
return;
}
}
else if ($("#drop_Card").val() == "护照")
{
if (huzhao.test(str) == false)
{
alert(‘对不起,您输入的护照证件号不正确!‘);
return;
}
}
})
showShangChao();
});