diff --git a/i18n-tool.js b/i18n-tool.js index a5e8847..f9625b6 100644 --- a/i18n-tool.js +++ b/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) + }, }