JS验证
//检查身份证号码和生日是否相同
function checkCardNo()
{
var blog = false;
var brithday = $('ctl00_HomeMasterContentPlaceHolder_txtBrithday').value;
var card = $('cardNoberPropt');
var type = $('ctl00_HomeMasterContentPlaceHolder_ddlCardType').value;
var nober = $('ctl00_HomeMasterContentPlaceHolder_CardNober').value;
brithday = brithday.substring(0,4)+brithday.substring(5,7)+brithday.substring(8,10);
//类型为0则是身份证
if(type=='0')
{
var propt = IsCard(nober);
if(propt=='验证通过')
{
if(nober.length == 15 || nober.length == 18)
{
switch(nober.length)
{
case 15:
{
if(nober.substring(6,12) == brithday)
{
blog = true;
}
else
{
card.innerHTML="证件号码和出生日期不匹配!";
alert('证件号码和出生日期不匹配!');
blog = false;
}
break;
}
case 18:
{
if(nober.substring(6,14) == brithday)
{
blog = true;
}
else
{
alert('证件号码和出生日期不相同!');
card.innerHTML="证件号码和出生日期不相同!";
blog = false;
}
break;
}
}
}
else
{
card.innerHTML="证件号码不合法!";
blog = false;
alert('证件号码不合法!');
//return false;
}
}
else
{
blog = false;
card.innerHTML=propt;
//return false;
}
}
if(blog)
{
document.getElementById("cardNoberPropt").style.display = "none";
}
}
//检查用户名中是否含有中文字符
function checkchinese(str)
{
var re1 = new RegExp("^[\u4E00-\uFA29]*$") //汉字的范围
var re2 = new RegExp("^[\uE7C7-\uE7F3]*$")
var str = str.replace(/(^\s*)|(\s*$)/g,'');
if (str == ''){return false;}
if (!(re1.test(str) && (! re2.test(str))))
{
return false;
}
return true;
}
//检查用户名中是否含有特殊字符
function replace(obj)
{
var str=obj.value;
var SPECIAL_STR = "~!@%^&*();'\"?><[]{}\\|,:/=+—“”‘";
for(i=0;i<str.length;i++)
if (SPECIAL_STR.indexOf(str.charAt(i)) !=-1)
{
$('usernamePropt').innerHTML = "不能以含有非法字符("+str.charAt(i)+")!";
obj.focus();
return false;
}
else
{
var reg = /^[\u4e00-\u9fa5]+$/i;
if (reg.test(str))
{
$('usernamePropt').innerHTML = "不能为汉字!";
obj.focus();
return false;
}
else
{
for(var i=0; i<str.length;i++)
{
if(reg.test(str.charAt(i)))
{
$('usernamePropt').innerHTML = "不能为汉字!";
obj.focus();
return false;
}
}
return true;
}
return true;
}
}
如果山不向我走来,我就向山走去!
![](http://www.cnblogs.com/Emoticons/baimantou/202015214.gif)