常用正则表达式收集

姓名验证--支持少数民族姓名:^([\u4e00-\u9fa5]|\u3007)+([\.\uff0e\u00b7\u30fb]?|\u3007?)+([\u4e00-\u9fa5]|\u3007)+$  
 
  身份证验证正则简易版:^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$  
 完整方法,严格限制:
function isIdCardNo(code) {
	if($.trim(code) == "") {	//不做空校验
		return true;
	}			
    if (/*code.length != 15 && */code.length != 18) {	//支持15或18位长度
        return false;
    }		    
    // 地区校验	
    var area = {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 :"国外"}		    
    if (area[parseInt(code.substr(0, 2))] == undefined) {
        return false;
    }
    
    switch (code.length) {	// 身份号码位数及格式校验
        case 18:
            if (!/^[0-9]{17}([0-9X])$/.test(code)) {	//基本格式校验
                return false;
            }
            //生日校验
            var strBirthday = code.substr(6, 4) + "/" + Number(code.substr(10, 2)) + "/" + Number(code.substr(12, 2));
            var dateBirthday = new Date(strBirthday);
            var flag = (strBirthday == (dateBirthday.getFullYear() + "/" + (dateBirthday.getMonth() + 1) + "/" + dateBirthday.getDate()));
            if(flag == false) {
            	return false;
            }	                
            //校验位校验
		    var idcardArr = code.split("");
            var index = ((parseInt(idcardArr[0]) + parseInt(idcardArr[10])) * 7 + 
                (parseInt(idcardArr[1]) + parseInt(idcardArr[11])) * 9 +
                (parseInt(idcardArr[2]) + parseInt(idcardArr[12])) * 10 + 
                (parseInt(idcardArr[3]) + parseInt(idcardArr[13])) * 5 + 
                (parseInt(idcardArr[4]) + parseInt(idcardArr[14])) * 8 + 
                (parseInt(idcardArr[5]) + parseInt(idcardArr[15])) * 4 + 
                (parseInt(idcardArr[6]) + parseInt(idcardArr[16])) * 2 + 
                 parseInt(idcardArr[7]) * 1 + 
                 parseInt(idcardArr[8]) * 6 +
                 parseInt(idcardArr[9]) * 3) % 11;
            return "10X98765432".substr(index, 1) == idcardArr[17];
            break;
        default:
            return false;
            break;
    }
    return true;
}

 

国内手机号验证:^1[3|4|5|8]\d{9}$

 

var phoneReg=/^1[3|4|5|8]\d{9}$/;
if (!phoneReg.test(value)) {
	return false;
}

   

 

国内银行卡号校验:^\d{16}|\d{19}$

 

6位数字校验:^\d{6}$

 

 

 

 

 推荐一个在线正则测试网址:http://tool.oschina.net/regex#  更多参考:10 Java Regular Expression Examples You Should Know 

 

 

 

你可能感兴趣的:(JavaScript)