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

View File

@ -1,5 +1,6 @@
// https://en.wikipedia.org/wiki/ISO_3166
// https://www.iso.org/obp/ui/#search
// https://www.chenweiliang.com/cwl-1354.html
module.exports = {
AD: {
@ -59,7 +60,7 @@ module.exports = {
iso3: 'ATG',
isoName: 'ANTIGUA AND BARBUDA',
isod: '028',
itc: '1 268',
itc: '1268',
legalstatus: '1',
name: { enUS: 'Antigua and Barbuda', zhCN: '安提瓜和巴布达', zhHK: '安提瓜和巴布达', zhTW: '安提瓜和巴布达' },
namefull: { enUS: '', zhCN: '安提瓜和巴布达' },
@ -75,7 +76,7 @@ module.exports = {
iso3: 'AIA',
isoName: 'ANGUILLA',
isod: '660',
itc: '1 264',
itc: '1264',
legalstatus: '2',
name: { enUS: 'Anguilla', zhCN: '安圭拉', zhHK: '安圭拉岛', zhTW: '英属安圭拉' },
namefull: { enUS: '', zhCN: '安圭拉' },
@ -171,7 +172,7 @@ module.exports = {
iso3: 'ASM',
isoName: 'AMERICAN SAMOA',
isod: '016',
itc: '1 684',
itc: '1684',
legalstatus: '2',
name: { enUS: 'American Samoa', zhCN: '美属萨摩亚', zhHK: '美属萨摩亚', zhTW: '美属萨摩亚' },
namefull: { enUS: '', zhCN: '美属萨摩亚' },
@ -283,7 +284,7 @@ module.exports = {
iso3: 'BRB',
isoName: 'BARBADOS',
isod: '052',
itc: '1 246',
itc: '1246',
legalstatus: '1',
name: { enUS: 'Barbados', zhCN: '巴巴多斯', zhHK: '巴巴多斯', zhTW: '巴巴多斯' },
namefull: { enUS: '', zhCN: '巴巴多斯' },
@ -427,7 +428,7 @@ module.exports = {
iso3: 'BMU',
isoName: 'BERMUDA',
isod: '060',
itc: '1 441',
itc: '1441',
legalstatus: '2',
name: { enUS: 'Bermuda', zhCN: '百慕大', zhHK: '百慕大', zhTW: '百慕大' },
namefull: { enUS: '', zhCN: '百慕大' },
@ -507,7 +508,7 @@ module.exports = {
iso3: 'BHS',
isoName: 'BAHAMAS',
isod: '044',
itc: '1 242',
itc: '1242',
legalstatus: '1',
name: { enUS: 'Bahamas', zhCN: '巴哈马', zhHK: '巴哈马', zhTW: '巴哈马' },
namefull: { enUS: 'the Commonwealth of The Bahamas', zhCN: '巴哈马联邦' },
@ -604,6 +605,9 @@ module.exports = {
isoName: 'CANADA',
isod: '124',
itc: '1',
phoneRegex: /^\d{10}$/.source,
phoneMaxlen: 10,
phoneMinlen: 10,
legalstatus: '1',
name: { enUS: 'Canada', zhCN: '加拿大', zhHK: '加拿大', zhTW: '加拿大' },
namefull: { enUS: '', zhCN: '加拿大' },
@ -764,14 +768,14 @@ module.exports = {
isoName: 'CHINA',
isod: '156',
itc: '86',
phoneRegex: /^1\d{10}$/.source,
phoneMaxlen: 11,
phoneMinlen: 11,
legalstatus: '1',
name: { enUS: 'China', native: '中国', zhCN: '中国', zhHK: '大陆', zhTW: '大陆' },
namefull: { enUS: "the People's Republic of China", zhCN: '中华人民共和国' },
notes:
'“GB/T 2659-2000”的“CN”适用于整个中华人民共和国辖区包括中国大陆、香港、澳门。而“ISO 3166-1”和“CNS 12842”的“CN”则仅适用于中国大陆不含港澳地区。',
phoneRegex: /^1\d{10}$/.source,
phoneMaxlen: 11,
phoneMinlen: 11,
timezone: '0',
},
CO: {
@ -959,7 +963,7 @@ module.exports = {
iso3: 'DMA',
isoName: 'DOMINICA',
isod: '212',
itc: '1 767',
itc: '1767',
legalstatus: '1',
name: { enUS: 'Dominica', zhCN: '多米尼克', zhHK: '多米尼克', zhTW: '多米尼克' },
namefull: { enUS: 'the Commonwealth of Dominica', zhCN: '多米尼克' },
@ -1248,7 +1252,7 @@ module.exports = {
iso3: 'GRD',
isoName: 'GRENADA',
isod: '308',
itc: '1 473',
itc: '1473',
legalstatus: '1',
name: { enUS: 'Grenada', zhCN: '格林纳达', zhHK: '格林纳达', zhTW: '格林纳达' },
namefull: { enUS: '', zhCN: '格林纳达' },
@ -1477,7 +1481,7 @@ module.exports = {
iso3: 'GUM',
isoName: 'GUAM',
isod: '316',
itc: '1 671',
itc: '1671',
legalstatus: '2',
name: { enUS: 'Guam', zhCN: '关岛', zhHK: '关岛', zhTW: '关岛' },
namefull: { enUS: '', zhCN: '关岛' },
@ -1797,7 +1801,7 @@ module.exports = {
iso3: 'JAM',
isoName: 'JAMAICA',
isod: '388',
itc: '1 876',
itc: '1876',
legalstatus: '1',
name: { enUS: 'Jamaica', zhCN: '牙买加', zhHK: '牙买加', zhTW: '牙买加' },
namefull: { enUS: '', zhCN: '牙买加共和国' },
@ -1830,11 +1834,11 @@ module.exports = {
isoName: 'JAPAN',
isod: '392',
itc: '81',
phoneRegex: /^\d{10,11}$/.source,
legalstatus: '1',
name: { enUS: 'Japan', native: '日本', zhCN: '日本', zhHK: '日本', zhTW: '日本' },
namefull: { enUS: '', zhCN: '日本国' },
notes: '',
phoneRegex: /^\d{10,11}$/.source,
timezone: '1',
},
KE: {
@ -1926,7 +1930,7 @@ module.exports = {
iso3: 'KNA',
isoName: 'SAINT KITTS AND NEVIS',
isod: '659',
itc: '1 869',
itc: '1869',
legalstatus: '1',
name: { enUS: 'Saint Kitts and Nevis', zhCN: '圣基茨和尼维斯', zhHK: '圣基茨和尼维斯', zhTW: '圣基茨和尼维斯' },
namefull: { enUS: '', zhCN: '圣基茨和尼维斯联邦' },
@ -1990,7 +1994,7 @@ module.exports = {
iso3: 'CYM',
isoName: 'CAYMAN ISLANDS',
isod: '136',
itc: '1 345',
itc: '1345',
legalstatus: '2',
name: { enUS: 'Cayman Islands', zhCN: '开曼群岛', zhHK: '开曼群岛', zhTW: '开曼群岛' },
namefull: { enUS: '', zhCN: '开曼群岛' },
@ -2054,7 +2058,7 @@ module.exports = {
iso3: 'LCA',
isoName: 'SAINT LUCIA',
isod: '662',
itc: '1 758',
itc: '1758',
legalstatus: '1',
name: { enUS: 'Saint Lucia', zhCN: '圣卢西亚', zhHK: '圣卢西亚', zhTW: '圣卢西亚' },
namefull: { enUS: '', zhCN: '圣卢西亚' },
@ -2390,7 +2394,7 @@ module.exports = {
iso3: 'MNP',
isoName: 'NORTHERN MARIANA ISLANDS',
isod: '580',
itc: '1 670',
itc: '1670',
legalstatus: '2',
name: { enUS: 'Northern Mariana Islands', zhCN: '北马里亚纳群岛', zhHK: '北马里亚纳群岛', zhTW: '北马里亚纳群岛' },
namefull: { enUS: 'the Commonwealth of the Northern Mariana Islands', zhCN: '北马里亚纳群岛邦' },
@ -2438,7 +2442,7 @@ module.exports = {
iso3: 'MSR',
isoName: 'MONTSERRAT',
isod: '500',
itc: '1 664',
itc: '1664',
legalstatus: '2',
name: { enUS: 'Montserrat', zhCN: '蒙塞拉特岛', zhHK: '蒙塞拉特岛', zhTW: '蒙塞拉特岛' },
namefull: { enUS: '', zhCN: '蒙特塞拉特' },
@ -3182,11 +3186,11 @@ module.exports = {
isoName: 'SINGAPORE',
isod: '702',
itc: '65',
phoneRegex: /^[89]\d{7}$/.source,
legalstatus: '1',
name: { enUS: 'Singapore', zhCN: '新加坡', zhHK: '新加坡', zhTW: '新加坡' },
namefull: { enUS: 'the Republic of Singapore', zhCN: '新加坡共和国' },
notes: '',
phoneRegex: /^[89]\d{7}$/.source,
timezone: '0',
},
SH: {
@ -3391,7 +3395,7 @@ module.exports = {
iso3: 'SXM',
isoName: 'SINT MAARTEN (DUTCH PART)',
isod: '534',
itc: '1 721',
itc: '1721',
legalstatus: '',
name: { enUS: 'Sint Maarten', zhCN: '荷属圣马丁', zhHK: '荷属圣马丁', zhTW: '荷属圣马丁' },
namefull: { zhCN: '荷属圣马丁' },
@ -3439,7 +3443,7 @@ module.exports = {
iso3: 'TCA',
isoName: 'TURKS AND CAICOS ISLANDS',
isod: '796',
itc: '1 649',
itc: '1649',
legalstatus: '2',
name: { enUS: 'Turks and Caicos Islands', zhCN: '特克斯和凯科斯群岛', zhHK: '特克斯和凯科斯群岛', zhTW: '土克斯及开科斯群岛' },
namefull: { enUS: '', zhCN: '特克斯与凯科斯群岛' },
@ -3631,7 +3635,7 @@ module.exports = {
iso3: 'TTO',
isoName: 'TRINIDAD AND TOBAGO',
isod: '780',
itc: '1 868',
itc: '1868',
legalstatus: '1',
name: { enUS: 'Trinidad and Tobago', zhCN: '特立尼达和多巴哥', zhHK: '特立尼达和多巴哥', zhTW: '特立尼达和多巴哥' },
namefull: { enUS: 'the Republic of Trinidad and Tobago', zhCN: '特立尼达和多巴哥共和国' },
@ -3727,7 +3731,7 @@ module.exports = {
iso3: 'UMI',
isoName: 'UNITED STATES MINOR OUTLYING ISLANDS',
isod: '581',
itc: '1 808',
itc: '1808',
legalstatus: '',
name: { enUS: 'U.S. Minor Outlying Islands', zhCN: '美国本土外小岛屿', zhHK: '美国海外小岛', zhTW: '美国边疆小岛' },
namefull: { enUS: '', zhCN: '美国本土外小岛屿' },
@ -3744,13 +3748,13 @@ module.exports = {
isoName: 'UNITED STATES',
isod: '840',
itc: '1',
phoneRegex: /^\d{10}$/.source,
phoneMaxlen: 10,
phoneMinlen: 10,
legalstatus: '1',
name: { enUS: 'United States', zhCN: '美国', zhHK: '美国', zhTW: '美国' },
namefull: { enUS: 'the United States of America', zhCN: '美利坚合众国' },
notes: '',
phoneRegex: /^\d{10}$/.source,
phoneMaxlen: 10,
phoneMinlen: 10,
timezone: '-13',
},
UY: {
@ -3811,7 +3815,7 @@ module.exports = {
iso3: 'VCT',
isoName: 'SAINT VINCENT AND THE GRENADINES',
isod: '670',
itc: '1 784',
itc: '1784',
legalstatus: '1',
name: { enUS: 'Saint Vincent and the Grenadines', zhCN: '圣文森特和格林纳丁斯', zhHK: '圣文森特和格林纳丁斯', zhTW: '圣文森特和格林纳丁斯' },
namefull: { enUS: '', zhCN: '圣文森特和格林纳丁斯' },
@ -3843,7 +3847,7 @@ module.exports = {
iso3: 'VGB',
isoName: 'VIRGIN ISLANDS (BRITISH)',
isod: '092',
itc: '1 284',
itc: '1284',
legalstatus: '2',
name: { enUS: 'British Virgin Islands', zhCN: '英属维尔京群岛', zhHK: '英属处女群岛', zhTW: '英属维尔京群岛' },
namefull: { enUS: 'British Virgin Islands', zhCN: '英属维京群岛' },
@ -3859,7 +3863,7 @@ module.exports = {
iso3: 'VIR',
isoName: 'VIRGIN ISLANDS (U.S.)',
isod: '850',
itc: '1 340',
itc: '1340',
legalstatus: '2',
name: { enUS: 'U.S. Virgin Islands', zhCN: '美属维尔京群岛', zhHK: '美属处女群岛', zhTW: '美属维尔京群岛' },
namefull: { enUS: 'the Virgin Islands of the United States', zhCN: '美属维京群岛' },

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)
},
}