diff --git a/i18n-lands.js b/i18n-lands.js index 6039989..72672a9 100644 --- a/i18n-lands.js +++ b/i18n-lands.js @@ -2,6 +2,25 @@ // https://www.iso.org/obp/ui/#search module.exports = { + validatePhone ({ phone } = {}) { + try { + let [fullphone, itc, callnumber] = /^\+(\d{1,3})-(\d{7,11})$/.exec(phone) + switch (itc) { + case this.CN.itc: + return this.CN.phonenumber.test(callnumber) + case this.SG.itc: + return this.SG.phonenumber.test(callnumber) + case this.US.itc: + return this.US.phonenumber.test(callnumber) + case this.JP.itc: + return this.JP.phonenumber.test(callnumber) + default: + return true + } + } catch (err) { + return false + } + }, AD: { domain: 'ad', indep: 'Yes', @@ -881,6 +900,7 @@ module.exports = { isod: '156', isoName: 'CHINA', itc: '86', + phonenumber: /^1\d{10}$/, legalstatus: '1', name: { enUS: 'China', @@ -2125,6 +2145,7 @@ module.exports = { isod: '392', isoName: 'JAPAN', itc: '81', + phonenumber: /^\d{10}$/, legalstatus: '1', name: { enUS: 'Japan', @@ -3749,6 +3770,7 @@ module.exports = { isod: '702', isoName: 'SINGAPORE', itc: '65', + phonenumber: /^[89]\d{7}$/, legalstatus: '1', name: { enUS: 'Singapore', zhCN: '新加坡', zhHK: '新加坡', zhTW: '新加坡' }, namefull: { enUS: 'the Republic of Singapore', zhCN: '新加坡共和国' }, @@ -4416,6 +4438,7 @@ module.exports = { isod: '840', isoName: 'UNITED STATES', itc: '1', + phonenumber: /^\d{10}$/, legalstatus: '1', name: { enUS: 'United States', zhCN: '美国', zhHK: '美国', zhTW: '美国' }, namefull: { enUS: 'the United States of America', zhCN: '美利坚合众国' }, diff --git a/i18n-phone.js b/i18n-phone.js deleted file mode 100644 index c52689a..0000000 --- a/i18n-phone.js +++ /dev/null @@ -1,25 +0,0 @@ -module.exports = { - CN: /^1\d{10}$/, - SG: /^[89]\d{7}$/, - US: /^\d{10}$/, - JP: /^\d{10}$/, - validatePhone ({ phone } = {}) { - try { - let [fullphone, areacode, callnumber] = /^\+(\d{1,3})-(\d{7,11})$/.exec(phone) - switch (areacode) { - case this.landSet['CN'].itc: - return this.CN.test(callnumber) - case this.landSet['SG'].itc: - return this.SG.test(callnumber) - case this.landSet['US'].itc: - return this.US.test(callnumber) - case this.landSet['JP'].itc: - return this.JP.test(callnumber) - default: - return true - } - } catch (err) { - return false - } - }, -} diff --git a/i18n.js b/i18n.js index a6fa346..47b6e4d 100644 --- a/i18n.js +++ b/i18n.js @@ -3,23 +3,4 @@ module.exports = { landSet: require('./i18n-lands.js'), currencySet: require('./i18n-currencies.js'), cryptocoinSet: require('./i18n-cryptocoins.js'), - validatePhone ({ phone } = {}) { - try { - let [fullphone, areacode, callnumber] = /^\+(\d{1,3})-(\d{7,11})$/.exec(phone) - switch (areacode) { - case this.landSet['CN'].itc: - return /^1\d{10}$/.test(callnumber) - case this.landSet['SG'].itc: - return /^[89]\d{7}$/.test(callnumber) - case this.landSet['US'].itc: - return /^\d{10}$/.test(callnumber) - case this.landSet['JP'].itc: - return /^\d{10}$/.test(callnumber) - default: - return true - } - } catch (err) { - return false - } - }, }