daddyz / phonelib

Ruby gem for phone validation and formatting using google libphonenumber library data
MIT License
1.04k stars 130 forks source link

Validation failures on valid phone numbers from UK (Channel Islands) #252

Open wilsonsilva opened 2 years ago

wilsonsilva commented 2 years ago

I'm getting many validation failures on different phone numbers from the British Channel Islands (for example, Jersey).

daddyz commented 2 years ago

@wilsonsilva thanks for reporting. This number is also parsed as invalid in original libphonenumber. You can check it here and open an issue for them. Gem's data is based on it. You can wait for them to fix it or you can use this method (in your app initializer) to add missing validation regex like here:

Phonelib.add_additional_regex :gb, Phonelib::Core::FIXED_LINE, '1534\d{6}'
agramichael commented 2 years ago

In case anyone finds this and wants to add support for all numbers from Channel Islands (Guernsey, Isle of Man & Jersey):

Phonelib.additional_regexes = [
  [:gb, :fixed_line, '1534\d{6}'],
  [:gb, :fixed_line, '1481\d{6}'],
  [:gb, :fixed_line, '1624\d{6}'],
  [:gb, :mobile, '7781\d{6}'],
  [:gb, :mobile, '7839\d{6}'],
  [:gb, :mobile, '7911\d{6}'],
  [:gb, :mobile, '7509\d{6}'],
  [:gb, :mobile, '7797\d{6}'],
  [:gb, :mobile, '7937\d{6}'],
  [:gb, :mobile, '7700\d{6}'],
  [:gb, :mobile, '7829\d{6}'],
  [:gb, :mobile, '7624\d{6}'],
  [:gb, :mobile, '7524\d{6}'],
  [:gb, :mobile, '7924\d{6}']
] 

I will be using this until there are other easy ways to validate phone numbers belonging to one country from a list, in this case: [:gb, ;gg, :im, :je]