phonelib icon indicating copy to clipboard operation
phonelib copied to clipboard

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

Open wilsonsilva opened this issue 4 years ago • 2 comments

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

wilsonsilva avatar Feb 15 '22 12:02 wilsonsilva

@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}'

daddyz avatar Feb 23 '22 05:02 daddyz

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]

agramichael avatar May 26 '22 16:05 agramichael