add validate_email

This commit is contained in:
陆柯 2023-07-26 10:36:59 +08:00
parent 37b5e1bea2
commit 40db44fc75

View File

@ -1,23 +1,26 @@
const landSet = require('./i18n-lands.js') const landSet = require('./i18n-lands.js')
module.exports = { module.exports = {
validate_phone ({ phone } = {}) { validate_phone ({ phone, level = wo?.envar?.phoneStrict || wo?.ss?.envarRemote?.phoneStrict || 'LEN' } = {}) {
try { try {
let [fullphone, itc, callnumber] = /^\+(\d{1,3})-(\d{7,12})$/.exec(phone) let [fullphone, itc, callnumber] = /^\+(\d{1,4})-(\d{7,12})$/.exec(phone)
switch (itc) { for (let land of Object.values(landSet)) {
case landSet.CN.itc: if (land.itc === itc) {
return new RegExp(landSet.CN.phoneRegex).test(callnumber) if (land.phoneRegex) {
case landSet.JP.itc: return new RegExp(land.phoneRegex).test(callnumber)
return new RegExp(landSet.JP.phoneRegex).test(callnumber) } else {
case landSet.SG.itc: return callnumber.length > (land.phoneMinlen || 7) && callnumber.length < (land.phoneMaxlen || 12)
return new RegExp(landSet.SG.phoneRegex).test(callnumber)
case landSet.US.itc:
return new RegExp(landSet.US.phoneRegex).test(callnumber)
default:
return true
} }
}
}
return false
} catch (error) { } catch (error) {
return false return false
} }
}, },
validate_email ({ email, format } = {}) {
if (format) return new RegExp(format).test(email)
return /^.+@[^\.]+\..+$/.test(email)
},
} }