一、手机号码正则
export const phoneReg = /^(0|86|17951)?1[123456789][0-9]{9}$/;
二、银行卡简单验证
export const idReg = /^([1-9]{1})(\d{14}|\d{15}|\d{16}|\d{17}|\d{18})$/;
三、身份证号正则校验
const valid = {
isChinaIDCard: function (StrNo) {
let res = {
tip: '验证成功',
value: true
};
StrNo = StrNo.toString();
if (StrNo.length === 0) {
res = {
tip: '请填写您的证件号码!',
value: false
};
return res;
} else if (StrNo.length === 18) {
if (valid.validateNumber(StrNo.substr(0, 17))) {
if (valid.validateCodeBy18IdCard(StrNo)) {
res = {
tip: '成功',
value: true
};
return res;
} else {
res = {
tip: '校验错误',
value: false
};
return res;
}
} else {
res = {
tip: '不是合法数字',
value: false
};
return res;
}
} else {
res = {
tip: '不是18位',
value: false
};
return res;
}
},
validateCodeBy18IdCard: function (StrNo) {
var Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1];
var ValideCode = [1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2];
var aIdCard = StrNo.split('');
var sum = 0;
if (aIdCard[17].toLowerCase() === 'x') {
aIdCard[17] = 10;
}
for (var i = 0; i < 17; i++) {
sum += Wi[i] * aIdCard[i];
}
var valCodePosition = sum % 11;
if (aIdCard[17].toString() === ValideCode[valCodePosition].toString()) {
return true;
} else {
return false;
}
},
validateNumber: function (oNum) {
if (/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$/.test(oNum)) {
return true;
}
}
};
module.exports = valid;
四、区分测试地址和生产地址
export function getUrl() {
return window.location.href.split('#')[0] + '#'
}
五、是否在APP内
export function isInApp() {
return (window.navigator.userAgent.match(/ylsystemid:kanyuhang&yl/ig))
}
六、是否在钉钉
export function isInDingding (){
var ua = window.navigator.userAgent.toLowerCase();
return /DingTalk/i.test(ua);
}
七、获取年月日时分秒
export function getTime(t){
let time = new Date(t)
let year = time.getFullYear()
let month = time.getMonth() + 1 < 10 ? '0' + (time.getMonth() + 1) : time.getMonth() + 1
let day = time.getDate() < 10 ? '0' + (time.getDate()) : time.getDate()
let hour = time.getHours()< 10 ? '0' + (time.getHours()) : time.getHours();
let min = time.getMinutes()< 10 ? '0' + (time.getMinutes()) : time.getMinutes();
let sec = time.getSeconds()< 10 ? '0' + (time.getSeconds()) : time.getSeconds();
return year+'-'+month+'-'+day+' '+hour+':'+min+':'+sec
}