var check={
var check = {
//是否为空
isNull: function (str) {
if ($.trim(str).length == 0)return true;
else return false;
},
//是否为邮件
isEmail: function (str) {
var reg = /^\w+((-w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
if (reg.test(str))return true;
},
//是否为手机号
isPhone: function (str) {
var a = /^1\d{10}$/, s = $.trim(str);
if (a.test(s))return true;
},
//是否汉字
isCN: function (str) {
var s = $.trim(str), reg = /^[\u4e00-\u9fa5]+$/;
if (reg.test(s))return true;
else return false;
},
//是否密码
isPwd: function (str) {
var reg = /^[A-Za-z0-9_-]+$/;
if (reg.test(str))return true;
},
//是否为微信号
isWx: function (str) {
var rex = /^[a-zA-Z\d_]{5,}$/;
if (rex.test($.trim(str)))return true;
return false;
},
//是否全为数字
isNum: function (num) {
var rex = /^[0-9]+$/;
if (rex.test($.trim(num)))return true;
return false;
},
//是否全为热线电话
isHotline: function (num) {
var rex = /^[0-9]([0-9]|-)*[0-9]$/;
if (rex.test($.trim(num)))return true;
return false;
},
//是否为钱数
isMoney: function (n) {
var rex = /^[0-9]+$/;
var num = n.trim();
var _this = this;
var numArr = num.toString().split('.');
var len = numArr.length;
var temp = 0;
if (len > 2)return false;
if (len == 2) {
var l = numArr[1].length;
var l1 = numArr[0].length;
if (l > 2) {
return false;
}
if (numArr[0].trim().length != l1)return false;
}
$.each(numArr, function (i) {
if (numArr[i] < 0 || !_this.isNum(numArr[i])) {
temp = 1
}
});
if (temp)return false;
return true;
},
//判断是否为url地址
isUrl: function (str) {
var rex = /^(http|https){1}:\/\/[^\s]+$/;
if (rex.test($.trim(str)))return true;
else return false;
}
}
使用方式
//str 为所需 验证字符
if(check.isNull(str)){
//dong something
}