From dc8861228339241e4cfefc816a623a12ef9874f9 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 27 Mar 2019 08:35:27 -0400 Subject: [PATCH] Bug 22594: Validate SMS messaging numbers using the E.164 format Many SMS messaging services reject numbers that do not conform to the E.164 international public telecommunication numbering plan. We already tell patrons on the OPAC "Please enter numbers only. (123) 456-7890 would be entered as 1234567890." but we do not enforce this. We should be validating the patron's SMS number on both the staff side and the patron self-service for updating the SMS number. Test plan: 1) Apply this patch 2) Enable SMS message ( you can set to Email to enable ) 3) Test entering and updating SMS numbers on the OPAC and staff interfaces. 4) Note you can only enter a 1 to 14 digit number with an optional + sign at the beginning ( used to indicate the number includes a country calling code ) Signed-off-by: Liz Rea --- .../intranet-tmpl/prog/en/includes/validator-strings.inc | 3 ++- .../intranet-tmpl/prog/en/modules/members/memberentrygen.tt | 1 + koha-tmpl/intranet-tmpl/prog/js/members.js | 12 ++++++++++++ koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc index 2ca4430ad7..6368e7b32e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/validator-strings.inc @@ -16,7 +16,8 @@ $(document).ready(function(){ rangelength: $.validator.format(_("Please enter a value between {0} and {1} characters long.")), range: $.validator.format(_("Please enter a value between {0} and {1}.")), max: $.validator.format(_("Please enter a value less than or equal to {0}.")), - min: $.validator.format(_("Please enter a value greater than or equal to {0}.")) + min: $.validator.format(_("Please enter a value greater than or equal to {0}.")), + phone: $.validator.format(_("Please enter a valid phone number.")) }); }); //]]> diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 99a0e8e877..54b5beb129 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -1096,6 +1096,7 @@ [% IF ( SMSSendDriver ) %]

+ SMS number should be in the format 1234567890 or +11234567890

[% UNLESS nosms_provider_id %]

diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js index e586e60d23..cfd3a830d4 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -309,6 +309,15 @@ $(document).ready(function(){ write_age(); } + $.validator.addMethod( + "phone", + function(value, element, phone) { + var e164 = "^\\+?[1-9]\\d{1,14}$"; + var re = new RegExp(e164); + return this.optional(element) || re.test(value); + }, + jQuery.validator.messages.phone); + $("#entryform").validate({ rules: { email: { @@ -326,6 +335,9 @@ $(document).ready(function(){ }, password2: { password_match: true + }, + SMSnumber: { + phone: true, } }, submitHandler: function(form) { diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt index 7a190c68ae..9f4e6f7908 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt @@ -133,7 +133,7 @@ [% IF ( SMSSendDriver ) %]

  1. Some charges for text messages may be incurred when using this service. Please check with your mobile service provider if you have questions.
  1. - + Please enter numbers only. (123) 456-7890 would be entered as 1234567890.
[% END %] -- 2.11.0