因为这段时间在做一些验证问题,用到了一些Jquery,每次使用都需要在网上查找一下,有些还是有点复杂,今天刚好没事,就自己总结一下,方便以后查询。都经过了测试,应该是没问题的。
<script type="text/javascript">
//判断字符串是否为空,为空就返回false,否则就返回true
function isNotnull(value){
if(value==null||value==""){
return false;
}else{
return true;
}
}
//判断字符串是否为全数字,是就返回true,否则就返回falsefunction isAllDigit(value){
if(isNaN(value)){
return false;
}else{
return true;
}
}
//判断是否是正确的邮箱格式,是就返回true,否则就返回false
function islegalEmail(value){
if(!value.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)){
return false;
}else{
return true;
}
}
//判断是否是正确的手机号码(11位),是就返回true,否则就返回false
function ismobileNumber(value){
var isMobile=/^(?:13\d|15\d)\d{5}(\d{3}|\*{3})$/;
if(!isMobile.test(value)){
return false;
}else{
return true;
}
}
//判断是否是正确的电话号码,是就返回true,否则就返回false
function isphoneNumber(value){
var isPhone=/^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
if(!isPhone.test(value)){
return false;
}else{
return true;
}
}
//判断是否是中文,是就返回true,否则就返回false
function isChineseWord(value){
var wordReg = /^[\u4e00-\u9fa5]+$/;
if(!wordReg.test(value)){
return false;
}else{
return true;
}
}
//判断输入的字符串只能为a-z,A-Z,0-9之间的字母
function isDraftWord(value){
if(!value.match(/^[a-zA-Z0-9]+$/)){
return false;
}else{
return true;
}
}
//判断是否是合法的网址,是就返回true,否则就返回false
function islegalUrl(value){
var regUrl= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
if (!value.match(regUrl)){
return false;
}else{
return true;
}
}
//判断是否是合法的IP,是就返回true,否则就返回false
function islegalIP(value){
var exp=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
if(!value.match(exp)){
return false;
}else{
return true;
}
}
//判断是否是合法的身份证号码,是就返回true,否则就返回false
function islegalCard(value){
var aCity = { 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: "国外 " }
var iSum = 0;
var info = "";value = value.replace(/x$/i, "a");
if (aCity[parseInt(value.substr(0, 2))] == null) return "Error:非法地区";
sBirthday = value.substr(6, 4) + "-" + Number(value.substr(10, 2)) + "-" + Number(value.substr(12, 2));
var d = new Date(sBirthday.replace(/-/g, "/"))
if (sBirthday != (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate())) return "Error:非法生日";
for (var i = 17; i >= 0; i--) iSum += (Math.pow(2, i) % 11) * parseInt(value.charAt(17 - i), 11)
if (iSum % 11 != 1) return "Error:非法证号";
return aCity[parseInt(value.substr(0, 2))] + "," + sBirthday + "," + (value.substr(16, 1) % 2 ? "男" : "女");
}
</script>