Fill in localized field for bad numbers, when prefix is okay #2

Closed
opened 2020-08-21 14:49:01 -07:00 by ajmas · 4 comments
ajmas commented 2020-08-21 14:49:01 -07:00 (Migrated from github.com)

I am using phoneparser as way for preparing phone numbers for presenting in a form (vue based app), where the country code and local phone number components are in separate fields.

In certain case the national component entered by the user will be invalid, even if the dialing code is valid. When the local number component is invalid, phoneparser won't fill in the localized field.

Some cases:

+1514578922 -> okay
+15145789223 -> localised portion not populated. expected: localised portion populated
+151457892 -> gives me country = Bangledesh (prefix +880).  expected: localised portion populated, US/Canada identification
I am using phoneparser as way for preparing phone numbers for presenting in a form (vue based app), where the country code and local phone number components are in separate fields. In certain case the national component entered by the user will be invalid, even if the dialing code is valid. When the local number component is invalid, phoneparser won't fill in the localized field. Some cases: ``` +1514578922 -> okay +15145789223 -> localised portion not populated. expected: localised portion populated +151457892 -> gives me country = Bangledesh (prefix +880). expected: localised portion populated, US/Canada identification ```
andyburke commented 2020-08-21 19:11:52 -07:00 (Migrated from github.com)

I get the following results:

> phoneparser.parse( '+1514578922' )
{
  valid: true,
  normalized: '+8801514578922',
  stripped: '1514578922',
  format: [Function: bound format],
  localized: { stripped: '1514578922', format: [Function: bound format] },
  info: { prefix: '1', type: 'mobile' },
  country: {
    name: {
      de: 'Bangladesch',
      es: 'Bangladesh',
      fr: 'Bangladesh',
      ja: 'バングラデシュ',
      it: 'Bangladesh',
      en: 'Bangladesh'
    },
    iso3166: {
      alpha2: 'BD',
      alpha3: 'BGD',
      independent: true,
      name: 'Bangladesh',
      numeric: 50,
      currency: [Object]
    },
    phone: { code: '880', lengths: [Array], prefixes: [Object] },
    latitude: 24,
    longitude: 90,
    timezones: [ 'UTC+06:00' ],
    area: 147570,
    population: 158875000,
    region: 'Asia',
    subregion: 'Southern Asia'
  }
}
> phoneparser.parse( '+15145789223' )
{
  valid: true,
  normalized: '+15145789223',
  stripped: '15145789223',
  format: [Function: bound format],
  localized: { stripped: '5145789223', format: [Function: bound format] },
  info: null,
  country: {
    name: {
      de: 'Vereinigte Staaten von Amerika',
      es: 'Estados Unidos',
      fr: 'États-Unis',
      ja: 'アメリカ合衆国',
      it: "Stati Uniti D'America",
      en: 'United States'
    },
    iso3166: {
      alpha2: 'US',
      alpha3: 'USA',
      independent: true,
      name: 'United States',
      numeric: 840,
      currency: [Object]
    },
    phone: { code: '1', lengths: [Array], prefixes: [Object] },
    latitude: 38,
    longitude: -97,
    timezones: [
      'UTC−12:00', 'UTC−11:00',
      'UTC−10:00', 'UTC−09:00',
      'UTC−08:00', 'UTC−07:00',
      'UTC−06:00', 'UTC−05:00',
      'UTC−04:00', 'UTC+10:00',
      'UTC+12:00'
    ],
    area: 9629091,
    population: 321645000,
    region: 'Americas',
    subregion: 'Northern America'
  }
}
> phoneparser.parse( '+1514578922' )
{
  valid: true,
  normalized: '+8801514578922',
  stripped: '1514578922',
  format: [Function: bound format],
  localized: { stripped: '1514578922', format: [Function: bound format] },
  info: { prefix: '1', type: 'mobile' },
  country: {
    name: {
      de: 'Bangladesch',
      es: 'Bangladesh',
      fr: 'Bangladesh',
      ja: 'バングラデシュ',
      it: 'Bangladesh',
      en: 'Bangladesh'
    },
    iso3166: {
      alpha2: 'BD',
      alpha3: 'BGD',
      independent: true,
      name: 'Bangladesh',
      numeric: 50,
      currency: [Object]
    },
    phone: { code: '880', lengths: [Array], prefixes: [Object] },
    latitude: 24,
    longitude: 90,
    timezones: [ 'UTC+06:00' ],
    area: 147570,
    population: 158875000,
    region: 'Asia',
    subregion: 'Southern Asia'
  }
}

The first and third look to be the same to me. The second one looks like a valid US/Canada number, and for me the localized portion seems to be correct.

The first and third examples are strange, can you give me some more info? Are they meant to be US numbers? If so, they're missing a digit. Are they meant to be numbers somewhere else but have +1 on the front?

I get the following results: ``` > phoneparser.parse( '+1514578922' ) { valid: true, normalized: '+8801514578922', stripped: '1514578922', format: [Function: bound format], localized: { stripped: '1514578922', format: [Function: bound format] }, info: { prefix: '1', type: 'mobile' }, country: { name: { de: 'Bangladesch', es: 'Bangladesh', fr: 'Bangladesh', ja: 'バングラデシュ', it: 'Bangladesh', en: 'Bangladesh' }, iso3166: { alpha2: 'BD', alpha3: 'BGD', independent: true, name: 'Bangladesh', numeric: 50, currency: [Object] }, phone: { code: '880', lengths: [Array], prefixes: [Object] }, latitude: 24, longitude: 90, timezones: [ 'UTC+06:00' ], area: 147570, population: 158875000, region: 'Asia', subregion: 'Southern Asia' } } ``` ``` > phoneparser.parse( '+15145789223' ) { valid: true, normalized: '+15145789223', stripped: '15145789223', format: [Function: bound format], localized: { stripped: '5145789223', format: [Function: bound format] }, info: null, country: { name: { de: 'Vereinigte Staaten von Amerika', es: 'Estados Unidos', fr: 'États-Unis', ja: 'アメリカ合衆国', it: "Stati Uniti D'America", en: 'United States' }, iso3166: { alpha2: 'US', alpha3: 'USA', independent: true, name: 'United States', numeric: 840, currency: [Object] }, phone: { code: '1', lengths: [Array], prefixes: [Object] }, latitude: 38, longitude: -97, timezones: [ 'UTC−12:00', 'UTC−11:00', 'UTC−10:00', 'UTC−09:00', 'UTC−08:00', 'UTC−07:00', 'UTC−06:00', 'UTC−05:00', 'UTC−04:00', 'UTC+10:00', 'UTC+12:00' ], area: 9629091, population: 321645000, region: 'Americas', subregion: 'Northern America' } } ``` ``` > phoneparser.parse( '+1514578922' ) { valid: true, normalized: '+8801514578922', stripped: '1514578922', format: [Function: bound format], localized: { stripped: '1514578922', format: [Function: bound format] }, info: { prefix: '1', type: 'mobile' }, country: { name: { de: 'Bangladesch', es: 'Bangladesh', fr: 'Bangladesh', ja: 'バングラデシュ', it: 'Bangladesh', en: 'Bangladesh' }, iso3166: { alpha2: 'BD', alpha3: 'BGD', independent: true, name: 'Bangladesh', numeric: 50, currency: [Object] }, phone: { code: '880', lengths: [Array], prefixes: [Object] }, latitude: 24, longitude: 90, timezones: [ 'UTC+06:00' ], area: 147570, population: 158875000, region: 'Asia', subregion: 'Southern Asia' } } ``` The first and third look to be the same to me. The second one looks like a valid US/Canada number, and for me the localized portion seems to be correct. The first and third examples are strange, can you give me some more info? Are they meant to be US numbers? If so, they're missing a digit. Are they meant to be numbers somewhere else but have +1 on the front?
ajmas commented 2020-08-22 18:57:36 -07:00 (Migrated from github.com)

They are all meant to be US/Canada numbers, but with only the first one being correct. The expectation is that they should all be identified as US/Canada numbers, based on prefix, even if they aren't valid based on length

They are all meant to be US/Canada numbers, but with only the first one being correct. The expectation is that they should all be identified as US/Canada numbers, based on prefix, even if they aren't valid based on length
andyburke commented 2020-08-24 20:09:56 -07:00 (Migrated from github.com)

Please see the 3.0.0 release phoneparser that uses the updated countrdata 3.0.0 release. I made some (I hope) improvements to the number matching that should hopefully address this.

For me, the first and third are still Bangladesh (since the lengths don't seem right for USA/CAN) but the middle example now resolves to CAN.

Please see the 3.0.0 release phoneparser that uses the updated countrdata 3.0.0 release. I made some (I hope) improvements to the number matching that should hopefully address this. For me, the first and third are still Bangladesh (since the lengths don't seem right for USA/CAN) but the middle example now resolves to CAN.
andyburke commented 2020-09-30 16:31:19 -07:00 (Migrated from github.com)

@ajmas please let me know if this is still an issue and I will reopen, but for now I am going to close.

@ajmas please let me know if this is still an issue and I will reopen, but for now I am going to close.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
andyburke/phoneparser#2
No description provided.