js比较常用自定义公共函数汇总
发布时间:2023-09-22 15:23:28 所属栏目:教程 来源:
导读:代码如下:
String.prototype.trim = function(){
return this.replace(/(^/s*)|(/s*$)/g, "");
}
//检查是否是日期格式
function isDate(datestr){
var result = datestr.match(/((^((1[8-9
String.prototype.trim = function(){
return this.replace(/(^/s*)|(/s*$)/g, "");
}
//检查是否是日期格式
function isDate(datestr){
var result = datestr.match(/((^((1[8-9
代码如下: String.prototype.trim = function(){ return this.replace(/(^/s*)|(/s*$)/g, ""); } //检查是否是日期格式 function isDate(datestr){ var result = datestr.match(/((^((1[8-9]/d{2})|([2-9]/d{3}))(-)(10|12|0?[13578])(-)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]/d{2})|([2-9]/d{3}))(-)(11|0?[469])(-)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]/d{2})|([2-9]/d{3}))(-)(0?2)(-)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^([1][89][0][48])(-)(0?2)(-)(29)$)|(^([2-9][0-9][0][48])(-)(0?2)(-)(29)$)|(^([1][89][2468][048])(-)(0?2)(-)(29)$)|(^([2-9][0-9][2468][048])(-)(0?2)(-)(29)$)|(^([1][89][13579][26])(-)(0?2)(-)(29)$)|(^([2-9][0-9][13579][26])(-)(0?2)(-)(29)$))/); if(result==null){ return "no"; } return "yes"; } //此方法以上面效果一致 function isDate2(datestr) { var result = datestr.match(/^(/d{1,4})(-|//)(/d{1,2})/2(/d{1,2})$/); if (result == null) return "no"; var d = new Date(result[1], result[3] - 1, result[4]); if((d.getFullYear() == result[1] && (d.getMonth() + 1) == result[3] && d.getDate() == result[4])){ return "yes"; } return "no"; } //判断输入的字符是否为中文 function IsChinese(str){ if(str.length!=0){ reg=/^[/u0391-/uFFE5]+$/; if(!reg.test(str)){ // alert("对不起,您输入的字符串类型格式不正确!"); return "no"; } } return "yes"; } //判断是否为空 function isEmpty(str){ if(str==null||typeof str=="undefined"||str.trim()==""){ return true; }else{ return false; } } //固定电话 function testTelephone(phone){ var phone_reg = new RegExp(/^([+]{0,1}/d{3,4}|/d{3,4}-)?/d{7,8}$/); if(!phone_reg.test(phone)){ return "no"; } return "yes"; } //折扣 function isDiscount(discount){ var phone_reg = new RegExp(/^(0([/.]/d{1,2})|1|1.00|1.0)$/); if(!phone_reg.test(discount)){ return "no"; } return "yes"; } //手机号码 function testMobile(mobile){ var mobile_reg = new RegExp(/^0{0,1}1[0-9]{10}$/); if(!mobile_reg.test(mobile)){ return "no"; } return "yes"; } //QQ号码从10000开始 function testQQ(qq){ var qq_reg = new RegExp(/^[1-9][0-9]{4,}$/); if(!qq_reg.test(qq)){ return "no"; } return "yes"; } //电子邮件 function testEmail(email){ var email_reg = new RegExp(/^/w+([-+.]/w+)*@/w+([-.]/w+)*./w+([-.]/w+)*$/); if(!email_reg.test(email)){ return "no"; } return "yes"; } //不带符号的正整数 function testPlusDigit(digit){ var plusDigit_reg = new RegExp(/^/d+$/); if(!plusDigit_reg.test(digit)){ return "no"; } return "yes"; } //DOUBLE价格 function testPriceFormat(str){ var priceFormatReg = new RegExp(/^/d+(./d{1,2})?$/); if(!priceFormatReg.test(str)){ return "no"; } return "yes"; } //身份证 function testIDCard(str){ (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐