27 lines
822 B
JavaScript
27 lines
822 B
JavaScript
const landSet = require('./i18n-lands.js')
|
|
|
|
module.exports = {
|
|
validate_phone ({ phone, level = wo?.envar?.phoneStrict || wo?.ss?.envarRemote?.phoneStrict || 'LEN' } = {}) {
|
|
try {
|
|
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)
|
|
},
|
|
}
|