//笔数验证(包括0跟正整数)
function checkParseInt(num) {
var reg = /^([0]|[1-9][0-9]*)$/;
if(reg.test(num)){
return true;
}else {
return false;
}
}
//金额验证(包括0跟小数点后两位)
function checkParseFloat(num) {
var reg = /^(([1-9]\d*)(\.\d{1,2})?)$|^(0\.0?([0-9]\d?))$|^(0)$/;
if(reg.test(num)){
return true;
}else {
return false;
}
}
//手机号加格式XXX XXXX XXXX
function mobileAddSpaceLogin (mobile){
mobile = this.spaceStrChangeMobile(mobile);
var myRe = /^[0-9]{4,11}$/g,
isNum = myRe.test(mobile),
newMobile = "";
if (isNum) {
if (mobile) for (var i = 1; i <= mobile.length; i++) newMobile += i % 4 === 0 ? " " + mobile[i - 1] : mobile[i - 1]
} else newMobile = mobile;
return newMobile;
}
//去手机空格
function spaceStrChangeMobile(str){
return str += "",
str = str.replace(/\ +/g, "")
}
//金额转换(格式:XXXX.XXXX.00)
function formatMoney (num) {
return (num.toFixed(2) + '').replace(/\d{1,4}(?=(\d{4})+(\.\d*)?$)/g, '$&,');
}
// 验证身份证 function checkIsIdCard(idCard) { var idCardReg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/; if(idCard == ""){ console.log("身份证号为空!"); return false; }else if(!idCardReg.test(idCard)) { console.log("身份证输入不合法!"); return false; } return true; } // 验证邮箱 function checkIsEmail(email) { var emailReg = /^[a-z0-9A-Z]+[- | a-z0-9A-Z . _]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$/; if(email == ""){ console.log("邮箱为空!"); return false; }else if(!emailReg.test(email)) { console.log("邮箱格式不合法!"); return false; } return true; }
//密码显示与否 function showEyes() { $(".eyesClose").on("touchend",function(){ var password = $("#password"); if(password.length>0){ if(password.attr('type') === 'password') { $(this).addClass('eyes'); password.attr('type', 'text'); } else { $(this).removeClass('eyes'); password.attr('type', 'password'); } } }); }
//倒计时显示 function showTimes(){ var countDown = 60; $('.getCodeBtn').val("重发("+countDown+")").attr("disabled",true); timer = setInterval(function() { countDown--; if(countDown) { $('.getCodeBtn').val("重发("+countDown+")").attr("disabled",true); }else { clearInterval(timer); countDown = parseInt($('#count-down').val()); $('.getCodeBtn').val('重发').attr("disabled",false); } }, 1000); }