把 validatePhone(...) 集成入 i18n-lands.js
This commit is contained in:
parent
419b8b4eda
commit
e0408f5000
@ -2,6 +2,25 @@
|
|||||||
// https://www.iso.org/obp/ui/#search
|
// https://www.iso.org/obp/ui/#search
|
||||||
|
|
||||||
module.exports = {
|
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: {
|
AD: {
|
||||||
domain: 'ad',
|
domain: 'ad',
|
||||||
indep: 'Yes',
|
indep: 'Yes',
|
||||||
@ -881,6 +900,7 @@ module.exports = {
|
|||||||
isod: '156',
|
isod: '156',
|
||||||
isoName: 'CHINA',
|
isoName: 'CHINA',
|
||||||
itc: '86',
|
itc: '86',
|
||||||
|
phonenumber: /^1\d{10}$/,
|
||||||
legalstatus: '1',
|
legalstatus: '1',
|
||||||
name: {
|
name: {
|
||||||
enUS: 'China',
|
enUS: 'China',
|
||||||
@ -2125,6 +2145,7 @@ module.exports = {
|
|||||||
isod: '392',
|
isod: '392',
|
||||||
isoName: 'JAPAN',
|
isoName: 'JAPAN',
|
||||||
itc: '81',
|
itc: '81',
|
||||||
|
phonenumber: /^\d{10}$/,
|
||||||
legalstatus: '1',
|
legalstatus: '1',
|
||||||
name: {
|
name: {
|
||||||
enUS: 'Japan',
|
enUS: 'Japan',
|
||||||
@ -3749,6 +3770,7 @@ module.exports = {
|
|||||||
isod: '702',
|
isod: '702',
|
||||||
isoName: 'SINGAPORE',
|
isoName: 'SINGAPORE',
|
||||||
itc: '65',
|
itc: '65',
|
||||||
|
phonenumber: /^[89]\d{7}$/,
|
||||||
legalstatus: '1',
|
legalstatus: '1',
|
||||||
name: { enUS: 'Singapore', zhCN: '新加坡', zhHK: '新加坡', zhTW: '新加坡' },
|
name: { enUS: 'Singapore', zhCN: '新加坡', zhHK: '新加坡', zhTW: '新加坡' },
|
||||||
namefull: { enUS: 'the Republic of Singapore', zhCN: '新加坡共和国' },
|
namefull: { enUS: 'the Republic of Singapore', zhCN: '新加坡共和国' },
|
||||||
@ -4416,6 +4438,7 @@ module.exports = {
|
|||||||
isod: '840',
|
isod: '840',
|
||||||
isoName: 'UNITED STATES',
|
isoName: 'UNITED STATES',
|
||||||
itc: '1',
|
itc: '1',
|
||||||
|
phonenumber: /^\d{10}$/,
|
||||||
legalstatus: '1',
|
legalstatus: '1',
|
||||||
name: { enUS: 'United States', zhCN: '美国', zhHK: '美国', zhTW: '美国' },
|
name: { enUS: 'United States', zhCN: '美国', zhHK: '美国', zhTW: '美国' },
|
||||||
namefull: { enUS: 'the United States of America', zhCN: '美利坚合众国' },
|
namefull: { enUS: 'the United States of America', zhCN: '美利坚合众国' },
|
||||||
|
@ -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
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
19
i18n.js
19
i18n.js
@ -3,23 +3,4 @@ module.exports = {
|
|||||||
landSet: require('./i18n-lands.js'),
|
landSet: require('./i18n-lands.js'),
|
||||||
currencySet: require('./i18n-currencies.js'),
|
currencySet: require('./i18n-currencies.js'),
|
||||||
cryptocoinSet: require('./i18n-cryptocoins.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
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user