地址转换
// 代码转中文
const codeToZH = (val,regData) => {
return regData.find( v => v.code === val )
}
// 繁体转简体 zh_t繁体 zh_s简体
const traditionalToSimplified = (val) => {
for (let i = 0; i < cc.length; i++) {
if (zh_t.indexOf(cc.charAt(i)) !== -1) {
str += zh_s.charAt(zh_t.indexOf(cc.charAt(i)))
} else {
str += cc.charAt(i)
}
}
return str
}
显示脱敏
// 手机号脱敏
const handlePhone = (phone) => {
return phone ? phone.replace(/^(.{3})(?:\d+)(.{4})$/, '$1****$2') : '-'
}
// 身份证脱敏
const handleIdCard = (id) => {
return id ? id.replace(/^(.{4})(?:\d+)(.{4})$/, '$1**********$2') : '-'
}
表单校验
// 手机号校验
const checkMobile = (mobile) => {
return RegExp(
"^((13[0-9])|(14(0|[5-7]|9))|(15([0-3]|[5-9]))|(16(2|[5-7]))|(17[0-8])|(18[0-9])|(19([0-3]|[5-9])))\\d{8}$"
).test(mobile);
}
// 邮箱校验
const checkEmail = (email) => {
return RegExp(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/)
.test(email);
}
//身份证验证
const checkIdentity = (msg) => {
let _IDRe18 = /^([1-6][1-9]|50)\d{4}(18|19|20)\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
let _IDre15 = /^([1-6][1-9]|50)\d{4}\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\d{3}$/
if (_IDRe18.test(msg) || _IDre15.test(msg)) {
return true
} else {
return false
}
}