Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/assets/javascripts/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ document.addEventListener('turbolinks:load', function() {
}
}
break;
case 'phone':
if (value) {
var phoneReg = /^[\+]?[0-9]{0,3}[-\s\.]?[(]?[0-9]{1,3}[)]?[-\s\.]?[0-9]{1,3}[-\s\.]?[0-9]{4,6}$/;
if (!phoneReg.test(value)) {
notify(this, 'Please enter a valid phone number');
success = false;
}
}
break;
case 'file-max-size':
if (
this.files &&
Expand Down
6 changes: 6 additions & 0 deletions app/models/questionnaire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ def vcs_url=(value)
super value
end

def phone=(value)
# strips the string to just numbers for standardization
value = value.try(:tr, '^0-9', '')
super value
end

def school
School.find(school_id) if school_id
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/questionnaires/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
= markdown(HackathonConfig['disclaimer_message'])

.form-inputs
= f.input :phone, label: "Phone number", input_html: { "data-validate" => "presence" }
= f.input :phone, label: "Phone number", input_html: { "data-validate" => ["presence", "phone"] }
= 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" }

= f.input :school_id, as: :school_selection, input_html: { "data-validate" => "presence" }
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/manage/questionnaires_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase
assert_equal @user.id, @questionnaire.checked_in_by_id
assert_equal true, @questionnaire.agreement_accepted
assert_equal true, @questionnaire.can_share_info
assert_equal "(123) 333-3333", @questionnaire.phone
assert_equal "1233333333", @questionnaire.phone
assert_equal "[email protected]", @questionnaire.email
assert_match /Checked in/, flash[:notice]
assert_response :redirect
Expand Down