标签:
//个人身份证
function checkEnergyCard(self){
var allowancePersonValue= $(self).val();
//是否为空
if(allowancePersonValue==""){
MS.messShow("身份证不能为空");
return false;
}else if(isCardNo(allowancePersonValue) === false){
//校验长度,类型
MS.messShow("您输入的身份证号码不正确,请重新输入");
return false;
}else if(checkProvince(allowancePersonValue) === false){
//检查省份
MS.messShow("您输入的身份证号码不正确,请重新输入");
return false;
}else if(checkBirthday(allowancePersonValue) === false){
//校验生日
MS.messShow("您输入的身份证号码生日不正确,请重新输入");
return false;
}else if(checkParity(allowancePersonValue) === false){
//检验位的检测
MS.messShow("您的身份证校验位不正确,请重新输入");
return false;
}else{
return true;
}
}
//身份证省的编码
var vcity = { 11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",
21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",
33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",
42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",
51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",
63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"
};
//检查号码是否符合规范,包括长度,类型
function isCardNo(card){
//身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/;
if(reg.test(card) === false){
return false;
}
return true;
}
//取身份证前两位,校验省份
function checkProvince(card){
var province = card.substr(0,2);
if(vcity[province] == undefined){
return false;
}
return true;
}
//检查生日是否正确
function checkBirthday(card){
var len = card.length;
//身份证15位时,次序为省(3位)市(3位)年(2位)月(2位)日(2位)校验位(3位),皆为数字
if(len == ‘15‘){
var re_fifteen = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/;
var arr_data = card.match(re_fifteen);
var year = arr_data[2];
var month = arr_data[3];
var day = arr_data[4];
var birthday = new Date(‘19‘+year+‘/‘+month+‘/‘+day);
return verifyBirthday(‘19‘+year,month,day,birthday);
}
//身份证18位时,次序为省(3位)市(3位)年(4位)月(2位)日(2位)校验位(4位),校验位末尾可能为X
if(len == ‘18‘){
var re_eighteen = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/;
var arr_data = card.match(re_eighteen);
var year = arr_data[2];
var month = arr_data[3];
var day = arr_data[4];
var birthday = new Date(year+‘/‘+month+‘/‘+day);
return verifyBirthday(year,month,day,birthday);
}
return false;
}
//校验日期
function verifyBirthday(year,month,day,birthday){
var now = new Date();
var now_year = now.getFullYear();
//年月日是否合理
if(birthday.getFullYear() == year && (birthday.getMonth() + 1) == month && birthday.getDate() == day){
//判断年份的范围(3岁到100岁之间)
var time = now_year - year;
if(time >= 3 && time <= 100){
return true;
}
return false;
}
return false;
}
//校验位的检测
function checkParity(card){
//15位转18位
card = changeFivteenToEighteen(card);
var len = card.length;
if(len == ‘18‘){
var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
var arrCh = new Array(‘1‘, ‘0‘, ‘X‘, ‘9‘, ‘8‘, ‘7‘, ‘6‘, ‘5‘, ‘4‘, ‘3‘, ‘2‘);
var cardTemp = 0, i, valnum;
for(i = 0; i < 17; i ++){
cardTemp += card.substr(i, 1) * arrInt[i];
}
valnum = arrCh[cardTemp % 11];
if (valnum == card.substr(17, 1)){
return true;
}
return false;
}
return false;
}
//15位转18位身份证号
function changeFivteenToEighteen(card){
if(card.length == ‘15‘){
var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
var arrCh = new Array(‘1‘, ‘0‘, ‘X‘, ‘9‘, ‘8‘, ‘7‘, ‘6‘, ‘5‘, ‘4‘, ‘3‘, ‘2‘);
var cardTemp = 0, i;
card = card.substr(0, 6) + ‘19‘ + card.substr(6, card.length - 6);
for(i = 0; i < 17; i ++){
cardTemp += card.substr(i, 1) * arrInt[i];
}
card += arrCh[cardTemp % 11];
return card;
}
return card;
}
//校验银行卡
function luhmCheck(bankno){
if(bankno==""||bankno==null){
MS.messShow("请输入银行卡");
return false;
}
var lastNum=bankno.substr(bankno.length-1,1);
var first15Num=bankno.substr(0,bankno.length-1);
var newArr=new Array();
for(var i=first15Num.length-1;i>-1;i--){
newArr.push(first15Num.substr(i,1));
}
var arrJiShu=new Array();
var arrJiShu2=new Array();
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();
var jishu_child2=new Array();
for(var h=0;h<arrJiShu2.length;h++){
jishu_child1.push(parseInt(arrJiShu2[h])%10);
jishu_child2.push(parseInt(arrJiShu2[h])/10);
}
var sumJiShu=0;
var sumOuShu=0;
var sumJiShuChild1=0;
var sumJiShuChild2=0;
var sumTotal=0;
for(var m=0;m<arrJiShu.length;m++){
sumJiShu=sumJiShu+parseInt(arrJiShu[m]);
}
for(var n=0;n<arrOuShu.length;n++){
sumOuShu=sumOuShu+parseInt(arrOuShu[n]);
}
for(var p=0;p<jishu_child1.length;p++){
sumJiShuChild1=sumJiShuChild1+parseInt(jishu_child1[p]);
sumJiShuChild2=sumJiShuChild2+parseInt(jishu_child2[p]);
}
sumTotal=parseInt(sumJiShu)+parseInt(sumOuShu)+parseInt(sumJiShuChild1)+parseInt(sumJiShuChild2);
var k= parseInt(sumTotal)%10==0?10:parseInt(sumTotal)%10;
var luhm= 10-k;
if(lastNum==luhm){
return true;
}
else{
MS.messShow("银行卡输入不正确");
return false;
}
}
//手机号 验证
function checkPhoneNo(self) {
var val = $(self).val();
var cellPhone = /^((\+86)?|\(\+86\))0?1[3578]\d{9}$/;
if (val == ‘‘ || val == null) {
MS.messShow("请输入您的手机号!");
return false;
} else if (!cellPhone.test(val)) {
MS.messShow("请输入正确的手机号!");
return false;
} else if (val.length > 11) {
MS.messShow("请输入正确的手机号!");
return false;
}
return true;
}
//密码 验证
function checkPassword(self) {
var pwd = $(self).val();
if (pwd == "" || pwd == null) {
MS.messShow("密码不能为空!");
return false;
} else if (pwd.length < 8 || pwd.length > 20) {
MS.messShow("密码长度为8-20位!");
return false;
} else if (/^[\d]*$|[\s]+/.test(pwd) | /^([a-zA-Z]+)$/.test(pwd)) {
MS.messShow("密码不能是纯数字或纯字母,不能包含空格!");
return false;
}
var pat = /^(?=[A-Za-z0-9~!@#$%^&*()_+{}|:"<>?`\-=[\]\\;‘,\./]*?[A-Za-z])(?=[A-Za-z0-9~!@#$%^&*()_+{}|:"<>?`\-=[\]\\;‘,\./]*?[0-9])[A-Za-z0-9~!@#$%^&*()_+{}|:"<>?`\-=[\]\\;‘,\./]{8,20}$/;
if (!pat.test(pwd)) {
MS.messShow("密码仅允许键盘可见特殊字符");
return false;
}
var pattern1 = new RegExp("[0-9]");
var pattern2 = new RegExp("[a-z]");
var pattern3 = new RegExp("[A-Z]");
var pattern4 = new RegExp(
"[`~!@#$^&*()=|{}‘:;‘,\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“‘。,、?]");
var num = 0;
if (pattern1.test(pwd)) {
num++;
}
if (pattern2.test(pwd)) {
num++;
}
if (pattern3.test(pwd)) {
num++;
}
if (pattern4.test(pwd)) {
num++;
}
if (num < 2) {
MS.messShow("您的密码级别太低!");
return false;
}
// num=2 弱; num=3 中; num=4 强;
return true;
}
//密码 验证 添加弱中强显示
function checkPassAdd(self) {
var pwd = $(self).val();
var pattern1 = new RegExp("[0-9]");
var pattern2 = new RegExp("[a-z]");
var pattern3 = new RegExp("[A-Z]");
var pattern4 = new RegExp(
"[`~!@#$^&*()=|{}‘:;‘,\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“‘。,、?]");
var num = 0;
if (pattern1.test(pwd)) {
num++;
}
if (pattern2.test(pwd)) {
num++;
}
if (pattern3.test(pwd)) {
num++;
}
if (pattern4.test(pwd)) {
num++;
}
// num=2 弱; num=3 中; num=4 强;
return num;
}
function checkName(self){
var nkName = $(self).val();
if (nkName == "" || nkName == null) {
MS.messShow("用户名不能为空!");
//$(self).val("用户名不能为空!");
//$(self).attr("placeholder", "用户名不能为空!");
return false;
}else if(nkName.length<6){
MS.messShow("用户名长度过短!");
//$(self).val("用户名长度过短!");
//$(self).attr("placeholder", "用户名长度过短!");
return false;
}else if(nkName.length>32){
MS.messShow("用户名长度过长!");
return false;
}else if(nkName.match("^[\\d]")){
MS.messShow("用户名不能以数字开头!");
return false;
}else if(!nkName.match("^[a-zA-Z0-9_]+$")){
MS.messShow("用户名只能包含字母、数字和‘_‘!");
return false;
}
return true;
}
//adit by lxq 将美元符号转成元
function toformartAmountRe(amount){
var toAmount = amount/10000
toAmount = formatMoney(toAmount,2,‘‘);
return toAmount;
}
//adit by lxq 将美元符号转成元
function formatMoney(number, places, symbol, thousand, decimal) {
number = number || 0;
places = !isNaN(places = Math.abs(places)) ? places : 2;
symbol = symbol !== undefined ? symbol : "$";
thousand = thousand || ",";
decimal = decimal || ".";
var negative = number < 0 ? "-" : "",
i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "")+symbol;
}
标签:
原文地址:http://www.cnblogs.com/baoliwei/p/4513619.html