Bug 22862: Normalize SMS messaging numbers before validating them

Librarians often copy and paste patron data, including phone numbers. SMS phone numbers are now being validated to conform to the E.164 specification. It would be nice to try to normalize that data by stripping non-numeric data from the paste (i.e. dashes, parens, etc ).

Test Plan:
1) Apply this patch
2) On the staff side, Attempt to enter invalid characters the SMS number field
3) Note you cannot enter invalid characters
4) Attempt to paste a phone number with invalid characters
5) Note those characters are removed on paste
6) Repeat these steps on the OPAC

Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Kyle M Hall 2019-05-07 14:53:29 -04:00 committed by Martin Renvoize
parent cc9d167af6
commit 115f4f2045
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
2 changed files with 28 additions and 0 deletions

View File

@ -315,6 +315,12 @@ $(document).ready(function(){
function(value, element, phone) {
var e164 = "^\\+?[1-9]\\d{1,14}$";
var re = new RegExp(e164);
let has_plus = value.charAt(0) === '+';
value = value.replace(/\D/g,'');
if ( has_plus ) value = '+' + value;
element.value = value;
return this.optional(element) || re.test(value);
},
jQuery.validator.messages.phone);

View File

@ -185,6 +185,28 @@
});
$("#info_digests").tooltip();
});
function normalizeSMS(value){
let has_plus = value.charAt(0) === '+';
let new_value = value.replace(/[^0-9]+/g, '');
if ( has_plus ) new_value = '+' + new_value;
return new_value;
}
var sms_input = document.getElementById('SMSnumber');
sms_input.addEventListener('keyup', function(){
var field = sms_input.value;
sms_input.value = normalizeSMS(field);
});
sms_input.addEventListener('paste', function(event) {
let paste = (event.clipboardData || window.clipboardData).getData('text');
setTimeout(function () {
sms_input.value = normalizeSMS(paste);
}, 100);
});
//]]>
</script>
[% END %]