标签:
/**
* 工具对象
*/
var Util = {
/**
* @param max: 允许输入字符最大长度
* @param obj: 输入内容的textarea 对象: $("#story")
* @param tipob: 提示内容对象 $("#tip")
* @param 调用: Util.tip(100,$("#story"),$("#tip"));
*/
tip:function(max,obj,tipobj){
var counter =obj.val().length; //获取文本域的字符串长度
tipobj.text(max-counter);
obj.on(‘keyup‘, function() {
var len = $(this).val().length;
if (len > max) {
var desc = $(this).val();
value = desc.substring(0,max);
obj.val(value); //超过的部分自动截取
return ;
}
tipobj.html(max-len);
});
},
/**
* form 下input,select,radio,textarea 对象的内容
*/
clear:function(formobj){
},
/**
* 是否是email
* /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
* /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
*/
isEmail:function(str){
return /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/.test(str);
},
/**
* 是否是手机
* /^1(3|5|8)[0-9]{9}$/;
*/
isMobile:function(str){
return /^13[\d]{9}$|14^[0-9]\d{8}|^15[0-9]\d{8}$|^18[0-9]\d{8}$/.test(str);
},
/**
* 是否是qq
*/
isQQ:function(str){
return /^[1-9]\d{3,10}$/.test(str);
},
/**
* 是否是身份证
* 身份证号码为15位或者18位,15位时全为数字,18位前17位为数字,最后一位是校验位,可能为数字或字符X
*/
isCard:function(str){
return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(str);
},
/**
* 是否是邮编
*/
isZcode:function(str){
return /^[0-9][0-9]{5}$/.test(str);
},
/**
* 是否是游戏id
*/
isGameId:function(str){
return /^[1-9](\d{3,})$/.test(str);
}
};标签:
原文地址:http://my.oschina.net/yonghan/blog/479239