首页 > 编程 > JavaScript > 正文

JQuery验证工具类搜集整理

2019-11-20 23:03:12
字体:
来源:转载
供稿:网友
复制代码 代码如下:

var Validator = {
// 邮箱
isEmail : function(s) {
var p = "^[-!#$%&/'*+//./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&/'*+///0-9=?A-Z^_`a-z{|}~]+/.[-!#$%&/'*+//./0-9=?A-Z^_`a-z{|}~]+$";
return this.test(s, p);
},

// 手机号码
isMobile : function(s) {
return this.test(s, /^(180|189|133|134|153|181)/d{8}$/);
},

// 电话号码
isPhone : function(s) {
return this.test(s, /^[0-9]{3,4}/-[0-9]{7,8}$/);
},

// 邮编
isPostCode : function(s) {
return this.test(s, /^[1-9][0-9]{5}$/);
},

// 数字
isNumber : function(s, d) {
return !isNaN(s.nodeType == 1 ? s.value : s)
&& (!d || !this.test(s, '^-?[0-9]*//.[0-9]*$'));
},

// 判断是否为空
isEmpty : function(s) {
return !jQuery.isEmptyObject(s);
},

// 正则匹配
test : function(s, p) {
s = s.nodeType == 1 ? s.value : s;
return new RegExp(p).test(s);
}
};
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表