u
This commit is contained in:
		
							parent
							
								
									a256e4fc34
								
							
						
					
					
						commit
						e18018f03c
					
				@ -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: {
 | 
			
		||||
@ -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: {
 | 
			
		||||
@ -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: {
 | 
			
		||||
@ -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: {
 | 
			
		||||
@ -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: {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										20
									
								
								i18n-tool.js
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								i18n-tool.js
									
									
									
									
									
								
							@ -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)
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user