diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3f91fa659..11a6c22da 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -127,7 +127,13 @@ private end def valid_phone_number?(number) - number.to_i.to_s == number && number.length >= 11 + numeric?(number) && number.length >= 11 + end + + def numeric?(str) + !Float(str).nil? + rescue StandardError + false end def format_error_messages diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 222d2ff04..f5703640c 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -346,6 +346,13 @@ RSpec.describe "User Features" do expect(page).to have_title("Error") end + it "allows telephone number in correct format" do + visit("users/new") + fill_in("user[phone]", with: "02345678910") + click_button("Continue") + expect(page).not_to have_content(/Enter a telephone number in the correct format/) + end + it "sets name, email, role, is_dpo and is_key_contact fields" do visit("users/new") fill_in("user[name]", with: "New User")