function verifyCompany(company){ //不能连续字符(如123、abc)连续3位或3位以上 if(!LxStr(company)){ $.ecCommon.ecAlert({ msg: '不允许录入3个连续或者重复数字、字母', }); return false; } //不能相同字符(如111、aaa)连续3位或3位以上 var re = /(\w)*(\w)\2{2}(\w)*/g; if(re.test(company)){ $.ecCommon.ecAlert({ msg: '不允许录入3个以上重复数字、字母', }); return false; } }
//不能连续字符(如123、abc)连续3位或3位以上
LxStr = function(str){
var arr = str.split('');
var flag = true;
for (var i = 1; i < arr.length-1; i++) {
var firstIndex = arr[i-1].charCodeAt();
var secondIndex = arr[i].charCodeAt();
var thirdIndex = arr[i+1].charCodeAt();
thirdIndex - secondIndex == 1;
secondIndex - firstIndex==1;
if((thirdIndex - secondIndex == 1)&&(secondIndex - firstIndex==1)){
flag = false;
}
}
if(!flag){
$.ecCommon.ecAlert({
msg: '不允许录入3个连续或者重复数字、字母',
});
return false;
}
return flag;
}
标签:字符,arr,false,验证,正则表达式,flag,secondIndex,var,return
From: https://www.cnblogs.com/Sincerity/p/18517840