49 lines
1.6 KiB
JavaScript
49 lines
1.6 KiB
JavaScript
module.exports = {
|
|
validate_phone ({ phone, format } = {}) {
|
|
try {
|
|
if (typeof format === 'string') {
|
|
return new RegExp(format).test(phone)
|
|
}
|
|
} 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) {
|
|
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
|
|
}
|
|
},
|
|
|
|
/*
|
|
- https://regex101.com/r/3uvtNl/1
|
|
/^((?:[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~]|(?<=^|\.)"|"(?=$|\.|@)|(?<=".*)[ .](?=.*")|(?<!\.)\.){1,64})(@)((?:[A-Za-z0-9.\-])*(?:[A-Za-z0-9])\.(?:[A-Za-z0-9]){2,})$/
|
|
- https://emailregex.com/
|
|
/^(([^<>()\[\]\\.,;:\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 } = {}) {
|
|
try {
|
|
if (typeof format === 'string') {
|
|
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)
|
|
},
|
|
}
|