// 银行卡号
var isCard= function(val){
var partten = /^(998801|998802|622525|622526|435744|435745|483536|528020|526855|622156|622155|356869|531659|622157|627066|627067|627068|627069)\d{10}$/;
// var partten = /^(-)?\d+(\.\d+)?$/;
return partten.test(val)
}
// 是否为数字
var isNumber = function(val){
var partten = /^\d+(\.\d+)?$/;
// var partten = /^(-)?\d+(\.\d+)?$/;
return partten.test(val)
}
//验证整数
var isInt = function(val){
var pattern = /^-?\d+$/;
return pattern.test(val);
};
//验证正整数
var isPositiveInt = function(val){
var pattern = /^[0-9]*[1-9][0-9]*$/;
return pattern.test(val);
}
//验证负整数
var isNegtiveInt = function(val){
var pattern = /^-[0-9]*[1-9][0-9]*$/;
return pattern.test(val);
}
//验证非负整数
var isNonnegativeInt = function(val){
var pattern = /^\d+$/;
return pattern.test(val);
}
//验证非正整数
var isNonPositiveInt = function(val){
var pattern = /^((-\d+)|(0+))$/;
return pattern.test(val);
}
//验证浮点数
var isFloat = function(val){
var pattern = /^(-?\d+)(\.\d+)?$/;
return pattern.test(val);
}
//验证正浮点数
var isPostiveFloat = function(val){
var pattern = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
return pattern.test(val);
}
//验证负浮点数
var isNegativeFloat = function(val){
var pattern = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/;
return pattern.test(val);
}
//验证非负浮点数
var isNonnegativeFloat = function(val){
var pattern = /^\d+(\.\d+)?$/;
return pattern.test(val);
}
//验证非正浮点数
var isNonPositiveFloat = function(val){
var pattern = /^((-\d+(\.\d+)?)|(0+(\.0+)?))$/;
return pattern.test(val);
}
//验证邮箱
var isEmail = function(val){
var pattern = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
return pattern.test(val);
}
//验证url
var isUrl = function(val){
var pattern = /^[a-zA-z]+:\/\/(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$/;
return pattern.test(val);
}
//验证账号用(数字、英文字母或者下划线)
var isAccount = function(val){
var pattern = /^\w+$/;
return pattern.test(val);
}
//验证手机
var isMobile = function(val){
var pattern = /^((\+?86)|(\(\+86\)))?(1[3456789][0-9]{9})$/;
return pattern.test(val);
}
//验证座机
var isTelephone = function(val){
var pattern = /^((\d{3,4}\-)|)\d{7,8}(|([-\u8f6c]{1}\d{1,5}))$/;
return pattern.test(val);
}
//验证邮编
var isPostalcode = function(val){
var pattern = /^[1-9]\d{5}(?!\d)$/;
return pattern.test(val);
}
//验证时间 HH:mm
var isTime = function(val){
var pattern = /^([01][0-9]|2[0-3]):[0-5][0-9]$/;
return pattern.test(val);
}
// 银行卡号码显示带*号
var isBank = function(val){
var pattern = val.replace(/\s/g,'').replace(/(\d{4})\d+(\d{4})$/, "**** **** **** $2")
return pattern;
// return pattern.test(val);
}
/*
var data = "3265986532146598";
console.log(data.replace(/\s/g,'').replace(/(\d{4})\d+(\d{4})$/, "**** **** **** $2"))
最后输出为:**** **** **** 6598
*/
// url取参数
function getUrlParam(key) {
var query = window.location.search.substring(1)
var vars = query.split("&")
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=")
if(pair[0] == key) {
return pair[1]
}
}
return null
}
/*
分页序号递增
*/
function paginationInc(currentPageNum = 1, currentPageSize = 10, dataIndex){
return (currentPageNum - 1) * currentPageSize + (dataIndex + 1);
}
js各种验证
最新推荐文章于 2024-04-20 14:59:10 发布