add validate_email
This commit is contained in:
parent
37b5e1bea2
commit
40db44fc75
29
i18n-tool.js
29
i18n-tool.js
@ -1,23 +1,26 @@
|
||||
const landSet = require('./i18n-lands.js')
|
||||
|
||||
module.exports = {
|
||||
validate_phone ({ phone } = {}) {
|
||||
validate_phone ({ phone, level = wo?.envar?.phoneStrict || wo?.ss?.envarRemote?.phoneStrict || 'LEN' } = {}) {
|
||||
try {
|
||||
let [fullphone, itc, callnumber] = /^\+(\d{1,3})-(\d{7,12})$/.exec(phone)
|
||||
switch (itc) {
|
||||
case landSet.CN.itc:
|
||||
return new RegExp(landSet.CN.phoneRegex).test(callnumber)
|
||||
case landSet.JP.itc:
|
||||
return new RegExp(landSet.JP.phoneRegex).test(callnumber)
|
||||
case landSet.SG.itc:
|
||||
return new RegExp(landSet.SG.phoneRegex).test(callnumber)
|
||||
case landSet.US.itc:
|
||||
return new RegExp(landSet.US.phoneRegex).test(callnumber)
|
||||
default:
|
||||
return true
|
||||
let [fullphone, itc, callnumber] = /^\+(\d{1,4})-(\d{7,12})$/.exec(phone)
|
||||
for (let land of Object.values(landSet)) {
|
||||
if (land.itc === itc) {
|
||||
if (land.phoneRegex) {
|
||||
return new RegExp(land.phoneRegex).test(callnumber)
|
||||
} else {
|
||||
return callnumber.length > (land.phoneMinlen || 7) && callnumber.length < (land.phoneMaxlen || 12)
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
} catch (error) {
|
||||
return false
|
||||
}
|
||||
},
|
||||
|
||||
validate_email ({ email, format } = {}) {
|
||||
if (format) return new RegExp(format).test(email)
|
||||
return /^.+@[^\.]+\..+$/.test(email)
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user