//考证用户名
//6-20位小写字母数字且以字母开首
function isUsername(subject){
var pattern = /^[a-z0-9]{6,20}$/;
return pattern.test(subject);
}
//考证暗码
//6-20位字母数字特殊符号
function isPassword(subject){
//var pattern = /^[a-zA-Z0-9!@#\$%\^&*()_.,?]{6,20}$/;
var pattern = /^[a-zA-Z0-9!@#\$%\^&*()_.,?]{6,16}$/;
return pattern.test(subject);
}
//考证码 //4位数字
function isCaptcha(subject){
var pattern = /^[0-9a-zA-Z]{4}$/;
return pattern.test(subject);
}
//考证短信 //4位数字
function isVerify(subject){
var pattern = /^[0-9]{4}$/;
return pattern.test(subject);
}
//考证手机
function isMobile(subject){
var pattern = /^1[3|4|5|7|8][0-9]{9}$/;
return pattern.test(subject);
}
//考证固话
function isTelephone(subject){
var pattern = /^[0-9]{3,4}-?[0-9]{8}$/;
return pattern.test(subject);
}
//考证邮编
function isZipcode(subject){
var pattern = /^[1-9][0-9]{5}$/;
return pattern.test(subject);
}
//考证邮箱
function isEmail(subject){
var pattern = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,4}$/;
return pattern.test(subject);
}
//考证中文姓名
function isChineseName(subject){
var pattern = /^[\u4e00-\u9fa5]{2,4}$/;
var str = subject.substr(0,1);
var surname = "赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华芦金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎绪鲁韦昌马苗凤花方俞任袁摄柳酆鲍史唐费廉岑薛雷贺倪汤 滕殷罗毕郝邬安常乐于时傅皮卞齐康伍余元卜顾孟平黄和穆萧尹姚邵堪汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董粱杜阮蓝闵席季麻强贾路娄危江童颜郭梅盛林刁钟徐邱骆高夏蔡田樊胡凌霍虞万支柯咎管卢莫经房裘缪干解应宗宣丁贲邓郁单杭洪包诸左石崔吉钮龚程嵇邢滑裴陆荣翁荀羊于惠甄魏加封芮羿储靳汲邴糜松 井段富巫乌焦巴弓牧隗山谷车侯宓蓬全郗班仰秋仲伊宫宁仇栾暴甘钭厉戎祖武符刘姜詹束龙恭弘=叶 恭弘幸司韶郜黎蓟薄印宿白怀蒲台从鄂索咸籍赖卓蔺屠蒙池乔阴霾胥能苍双 闻莘党翟谭贡劳逄姬申扶堵冉宰郦雍郤璩桑桂濮牛寿通边扈燕冀郏浦尚农温别庄晏柴瞿阎充慕连茹习宦艾鱼容向古易慎戈廖庚终暨居衡步都耿满弘匡国文寇广禄阙东 殴殳沃利蔚越夔隆师巩厍聂晁勾敖融冷訾辛阚那简饶空曾毋沙乜养鞠须丰巢关蒯相查后江红游竺权逯盖益桓公万俟司马上官欧阳夏侯诸葛闻人东方赫连皇甫尉迟公羊 澹台公冶宗政濮阳淳于仲孙太叔申屠公孙乐正轩辕令狐钟离闾丘长孙慕容鲜于宇文司徒司空亓官司寇仉督子车颛孙端木巫马公西漆雕乐正壤驷公良拓拔夹谷宰父谷粱 晋楚闫法汝鄢喜涂钦段干百里东郭南门呼延妫海羊舌微生岳帅缑亢况后有琴梁丘左丘东门西门商牟佘佴伯赏南宫墨哈谯笪年爱阳佟第五言福兰覃宛战昝肖荆景付渠";
var result = surname.search(str);
return pattern.test(subject) && (result != -1);
}
//身份证考证
function idcard_verify_number(idcard_base){
if(idcard_base.length != 17){
return false;
}
//加权因子
var factor = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
//校验码对应值
var verify_number_list = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
var checksum = 0;
for (i = 0; i < idcard_base.length; i++){
checksum += idcard_base.substr(i, 1) * factor[i];
}
mod = checksum % 11;
verify_number = verify_number_list[mod];
return verify_number;
}
//18位身份证校验码有效性搜检
function isIdcard(str){
if(str.length != 18){
return false;
}
var idcard_base = str.substr(0, 17);
if(idcard_verify_number(idcard_base) != str.substr(17, 1).toUpperCase()){
return false;
}
return true;
}
//提现金额
function isWithdraw(withdraw){
var pattern = /^\d+(.)?\d{1,2}$/;
return pattern.test(withdraw);
}
//整数
function isInteger(number){
var pattern = /^\d+$/;
return pattern.test(number);
}
//浮点
function isFloat(number){
// var pattern = /^\d+(.)?\d{1,2}$/;
var pattern = /^[+]?(([1-9]\d*[.]?)|(0.))(\d{0,2})?$/;
return pattern.test(number);
}
//设置用户名 考证用户名
function isUname(subject){
//6-20位小写字母数字且以字母开首
var pattern = /^[a-z][a-z0-9]{5,19}$/;
return pattern.test(subject);
}
用法举例:
var mobile =$.trim($(“#mobile”).val());
if(mobile == “”){
layer.tips('请输入手机号码', '#mobile', {time: 3});
return false;
}
if( ! isMobile(mobile)){
layer.tips('手机号码花样输入有误,请从新输入', '#mobile', {time: 3});
$("#mobile").focus();
return false;
}