js 各种校验
2021-06-15 00:03
标签:ack nbsp bsp als ctc reg test time check js 各种校验 标签:ack nbsp bsp als ctc reg test time check 原文地址:http://www.cnblogs.com/w-ym/p/7278203.html//非0 并且大于0 可以是小数----demo1
//日期转化成为yyyy-mm-dd ----demo2
//校验手机号是否是正确---------demo3
//demo1
function isInteger(obj) {
reg = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
if (reg.test(obj)) {
return false;
} else {
return true;
}
}//demo2
function DateObjectConvertJSDate(obj){
var date = new Date(obj.time);
var seperator1 = "-";
var seperator2 = ":";
var year = date.getFullYear();
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month ) {
month = "0" + month;
}
if (strDate >= 0 && strDate ) {
strDate = "0" + strDate;
}
var currentdate = year + seperator1 + month + seperator1 + strDate;
return currentdate;
}
//demo3
function checkMobile(str){
var regu =/^[1][3][0-9]{9}$/;
if (regu .test(str)) {
return true;
}else{
return false;
}
}
下一篇:JSON转FormData