This commit is contained in:
Luk Lu
2023-07-27 19:18:06 +08:00
parent a256e4fc34
commit e18018f03c
2 changed files with 48 additions and 36 deletions

View File

@@ -1,11 +1,19 @@
const landSet = require('./i18n-lands.js')
module.exports = {
validate_phone ({ phone, level = wo?.envar?.phoneStrict || wo?.ss?.envarRemote?.phoneStrict || 'LEN' } = {}) {
validate_phone ({ phone, format } = {}) {
try {
if (typeof format === 'string') {
return new RegExp(format).test(callnumber)
}
} catch (exp) {
console.log('Invalid phone format: ', format)
}
try {
let [fullphone, itc, callnumber] = /^\+(\d{1,4})-(\d{7,12})$/.exec(phone)
let landSet = wo?.i18n?.landSet || wo?.ss?.i18n?.landSet || {}
for (let land of Object.values(landSet)) {
if (land.itc === itc) {
console.log(land)
if (land.phoneRegex) {
return new RegExp(land.phoneRegex).test(callnumber)
} else {
@@ -26,16 +34,16 @@ module.exports = {
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
*/
validate_email ({ email, format } = {}) {
let regex =
/^((?:[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~]|(?<=^|\.)"|"(?=$|\.|@)|(?<=".*)[ .](?=.*")|(?<!\.)\.){1,64})(@)((?:[A-Za-z0-9.\-])*(?:[A-Za-z0-9])\.(?:[A-Za-z0-9]){2,})$/
try {
if (typeof format === 'string') {
regex = new RegExp(format)
return new RegExp(format).test(email)
}
} catch (exp) {
console.log('Invalid email format: ', format)
}
let regex =
/^((?:[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~]|(?<=^|\.)"|"(?=$|\.|@)|(?<=".*)[ .](?=.*")|(?<!\.)\.){1,64})(@)((?:[A-Za-z0-9.\-])*(?:[A-Za-z0-9])\.(?:[A-Za-z0-9]){2,})$/
return regex.test(email)
},
}