*
//邮箱验证
function checkEmail() {
var emailReg = /^\w+@[a-zA-Z0-9]{2,10}(?:\.[a-z]{2,4}){1,3}$/;
var emailResult = email.value;
if(emailReg.test(emailResult)){
email_notice.innerHTML = '邮箱验证通过!';
email_notice.style.color = 'green';
return true;
}else {
email_notice.innerHTML = '邮箱验证未通过,请重新输入!';
email_notice.style.color = 'red';
return false;
}
}
*
//手机号码验证
function checkPhone() {
var phoneReg = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
var phoneResult = phone.value;
if(phoneReg.test(phoneResult)){
phone_notice.innerHTML = '手机号码验证通过!';
phone_notice.style.color = 'green';
return true;
}else {
phone_notice.innerHTML = '手机号码验证未通过!';
phone_notice.style.color = 'red';
return false;
}
}
*
2.函数方法:(包含Luhm验证)
//银行卡号验证
function checkBankCardNumber() {
//长度校验
var bankcardnumberResult = bankcardnumber.value;
if(bankcardnumberResult == "" || bankcardnumberResult.length < 16 || bankcardnumberResult.length > 19) {
bankcardnumber_notice.innerHTML = "银行卡号位数必须在16~19之间,请完整输入银行卡号!";
bankcardnumber_notice.style.color = 'red';
return false;
}
//开头6位校验
var strBin="10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99";
if(strBin.indexOf(bankcardnumberResult.substring(0, 2)) == -1) {
bankcardnumber_notice.innerHTML = "银行卡号开头6位不符合规范,请检查后重新输入!";
bankcardnumber_notice.style.color = 'red';
return false;
}
//全数字校验
var num = /^\d*$/;
if(!num.exec(bankcardnumberResult)) {
bankcardnumber_notice.innerHTML = "银行卡号必须全为数字,请检查后重新输入!";
bankcardnumber_notice.style.color = 'red';
return false;
}
//Luhm验证
var lastNum=bankcardnumberResult.substr(bankcardnumberResult.length-1,1);//取出最后一位(与luhm进行比较)
var first15Num=bankcardnumberResult.substr(0,bankcardnumberResult.length-1);//前15或18位
var newArr = new Array();
for(var i=first15Num.length-1;i>-1;i--){ //前15或18位倒序存进数组
newArr.push(first15Num.substr(i,1));
}
var arrJiShu = new Array(); //奇数位*2的积 <9
var arrJiShu2 = new Array(); //奇数位*2的积 >9
var arrOuShu = new Array(); //偶数位数组
for(var j = 0; j < newArr.length; j++){
if( (j+1)%2 == 1) { //奇数位
if(parseInt(newArr[j])*2 < 9)
arrJiShu.push(parseInt(newArr[j])*2);
else
arrJiShu2.push(parseInt(newArr[j])*2);
}else //偶数位
arrOuShu.push(newArr[j]);
}
var jishu_child1 = new Array();//奇数位*2 >9 的分割之后的数组个位数
var jishu_child2 = new Array();//奇数位*2 >9 的分割之后的数组十位数
for(var h=0; h9 的分割之后的数组个位数之和
var sumJiShuChild2 = 0; //奇数位*2 >9 的分割之后的数组十位数之和
var sumTotal = 0;
for(var m = 0; m
submitHandler: function (form){
if(checkEmail()){
if(checkPhone()) {
if(checkBankCardNumber()){
loading('正在提交,请稍等...');
form.submit();
}else {
alert("银行卡号验证未通过! ");
return false;
}
}else {
alert("手机号码验证未通过! ");
return false;
}
}else{
alert("邮箱验证未通过! ");
return false;
}
}
/ *小白一个,仅留做自我学习记忆,时常修改,有不对不全之处还望不吝赐教!* /