diff --git a/app/helpers/contact_helper.rb b/app/helpers/contact_helper.rb index 2bd86937f..1944d62d3 100644 --- a/app/helpers/contact_helper.rb +++ b/app/helpers/contact_helper.rb @@ -31,7 +31,7 @@ module ContactHelper end def valid_number?(full_name) - full_name.gsub(/\s+/, '').match?(/\A\+?\d+\z/) + TelephoneNumber.parse(full_name).valid? end def single_word_name_hash(full_name) diff --git a/spec/helpers/contact_helper_spec.rb b/spec/helpers/contact_helper_spec.rb index 41953fb8d..c4f271e4b 100644 --- a/spec/helpers/contact_helper_spec.rb +++ b/spec/helpers/contact_helper_spec.rb @@ -63,8 +63,8 @@ RSpec.describe ContactHelper do end it 'handle name with mobile number with spaces correctly' do - full_name = '+1 234 567 890' - expected_result = { first_name: '+1 234 567 890', last_name: nil, middle_name: nil, prefix: nil, suffix: nil } + full_name = '+1 423-423-4234' + expected_result = { first_name: '+1 423-423-4234', last_name: nil, middle_name: nil, prefix: nil, suffix: nil } expect(helper.parse_name(full_name)).to eq(expected_result) end