国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > web前端 > jquery > jQuery验证邮箱/数字/是否为空等代码

jQuery验证邮箱/数字/是否为空等代码

来源:程序员人生   发布时间:2014-02-04 21:45:02 阅读次数:3462次

jQuery验证邮箱/数字/是否为空等,代码如下:

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);
}
};

生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生