1. common.js
1.1.1. 相关的正则表达式
function LEMONUtils() {}
LEMONUtils.testFn = {
isPassword : function(s) {
return /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^.{6,20}$/.test(s);
},
isEmail : function(s) {
var isEmailText = /^(?=\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$).{0,30}$/;
return isEmailText.test(s);
},
isMobile : function(s) {
var re=/^1[3-8]\d{9}$/;
return re.test(s);
},
isZipCode : function(s) {
var re = /^[1-9][0-9]{5}$/;
return re.test(s);
},
isNumber:function(s) {
var re = /^[0-9]*$/;
return re.test(s);
},
isQQ:function(s) {
var re = /^[1-9]*$/;
return re.test(s);
},
isNickname:function(s){
var re =/^[\u4E00-\u9FA5]{2,5}$/;
return re.test(s);
},
isMoney: function(s) {
var re = /^\d*(\.\d{1,2})?$|^\d*\.(\d{1,2})?$/;
return re.test(s);
},
isChinese: function(value) {
return /^[\u4e00-\u9fa5]+$/.test(value);
},
isNum: function(value) {
return /^[0-9]+$/.test(value);
},
isEnglish: function(value) {
return /^[a-zA-Z]+$/.test(value);
},
isPwd: function(value) {
return /^[a-zA-Z0-9]+$/.test(value);
},
isUname: function(value) {
return /^[a-zA-Z0-9\u4E00-\u9FA5]+$/.test(value);
},
isMoney: function(data, isPositive) {
return isPositive ? /^\d+(\.\d{1,2})?$/.test(data) && parseFloat(data) > 0 : /^(-)?\d+(\.\d{1,2})?$/.test(data);
},
isIdCard: function(idCard) {
var regIdCard = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
if (regIdCard.test(idCard)) {
if (idCard.length == 18) {
var idCardWi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
var idCardY = new Array(1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2);
var idCardWiSum = 0;
for (var i = 0; i < 17; i++) {
idCardWiSum += idCard.substring(i, i + 1) * idCardWi[i];
}
var idCardMod = idCardWiSum % 11;
var idCardLast = idCard.substring(17);
if (idCardMod == 2) {
if (idCardLast == 'X' || idCardLast == 'x') {
return true;
} else {
return false;
}
} else {
if (idCardLast == idCardY[idCardMod]) {
return true;
} else {
return false;
}
}
}
} else {
return false;
}
return true;
},
isBankCard: function(bankCard) {
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";
var lastNum = bankCard.substr(bankCard.length - 1, 1);
var first15Num = bankCard.substr(0, bankCard.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 (strBin.indexOf(bankCard.substring(0, 2)) == -1) {
return false;
}
if (!(lastNum == luhm)) {
return false;
}
return true;
},
isEmail: function(value) {
return /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(value);
}
}
1.1.2. 获取url中参数值
function LEMONUtils() {}
LEMONUtils.getQueryString = function(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = decodeURIComponent(top.location.search).substr(1).match(reg);
if (r != null) return unescape(r[2]);
return "";
}