Skip to content

Commit 09167ae

Browse files
JeremyRudmancbaudouinjrpeterkos
authored
fix(questionnaire): added phone number requirements (#283)
* fix(questionnaire): added phone number requirement using a regex to require users to input a valid phone number and stripped non numbers from the stored value with the exception of the country code * fix(questionnaire): edited callback to pass test edit call back that removes non-numbers from phone number to pass testing * fix(questionnaire): edited test to fail with phone formatting edited test to fail if the phone # formating is still there when saved into the database. Also stopped exception for "+" as it was not necessary. * fix(questionnaire): fixed comment about phone number stripping * fix: houndci formatting comments * fix: earlier fix was incorrect. correct houndci fix * fix(phone): implmented changed phone number regex for validation implement suggested regex although made internation extention 3 instead of 2 digits long for max length * fix(questionnaire): added support for more international numbers made the numbers regex more flexable to support more international numbers such as in Nigeria with two digit area codes. * Phone validation hit, remove duplicate check Co-authored-by: Chris Baudouin, Jr <[email protected]> Co-authored-by: Peter Kos <[email protected]>
1 parent c9d6658 commit 09167ae

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

app/assets/javascripts/validate.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ document.addEventListener('turbolinks:load', function() {
4040
}
4141
}
4242
break;
43+
case 'phone':
44+
if (value) {
45+
var phoneReg = /^[\+]?[0-9]{0,3}[-\s\.]?[(]?[0-9]{1,3}[)]?[-\s\.]?[0-9]{1,3}[-\s\.]?[0-9]{4,6}$/;
46+
if (!phoneReg.test(value)) {
47+
notify(this, 'Please enter a valid phone number');
48+
success = false;
49+
}
50+
}
51+
break;
4352
case 'file-max-size':
4453
if (
4554
this.files &&

app/models/questionnaire.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ def vcs_url=(value)
138138
super value
139139
end
140140

141+
def phone=(value)
142+
# strips the string to just numbers for standardization
143+
value = value.try(:tr, '^0-9', '')
144+
super value
145+
end
146+
141147
def school
142148
School.find(school_id) if school_id
143149
end

app/views/questionnaires/_form.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
= markdown(HackathonConfig['disclaimer_message'])
1111

1212
.form-inputs
13-
= f.input :phone, label: "Phone number", input_html: { "data-validate" => "presence" }
13+
= f.input :phone, label: "Phone number", input_html: { "data-validate" => ["presence", "phone"] }
1414
= f.input :date_of_birth, start_year: Date.today.year - 5, end_year: Date.today.year - 90, order: [:month, :day, :year], input_html: { "data-validate" => "presence" }
1515

1616
= f.input :school_id, as: :school_selection, input_html: { "data-validate" => "presence" }

test/controllers/manage/questionnaires_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase
390390
assert_equal @user.id, @questionnaire.checked_in_by_id
391391
assert_equal true, @questionnaire.agreement_accepted
392392
assert_equal true, @questionnaire.can_share_info
393-
assert_equal "(123) 333-3333", @questionnaire.phone
393+
assert_equal "1233333333", @questionnaire.phone
394394
assert_equal "[email protected]", @questionnaire.email
395395
assert_match /Checked in/, flash[:notice]
396396
assert_response :redirect

0 commit comments

Comments
 (0)