From: Thomas Berezansky Date: Mon, 13 Jun 2011 05:01:52 +0000 (-0400) Subject: Regex check for "last 4 digits of phone number" X-Git-Tag: sprint4-merge-nov22~5152 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=353e6ce078a37a2f5b8c3c581602bd9fa36ce0c7;p=working%2FEvergreen.git Regex check for "last 4 digits of phone number" If the day_phone regex (direct or from generic phone) has a capture group use it as the "last 4 digits". For example, you might configure this for day_phone regex: [2-9]\d{2}-\d{3}-(\d{4})( x\d+)? With this patch the extension will be ignored for the last 4 digits. Note: Does not require that the "last 4 digits" capture group actually contain 4 digits. Signed-off-by: Thomas Berezansky Signed-off-by: Jason Etheridge --- diff --git a/Open-ILS/web/js/ui/default/actor/user/register.js b/Open-ILS/web/js/ui/default/actor/user/register.js index ac9b45cd32..3fe41b85c6 100644 --- a/Open-ILS/web/js/ui/default/actor/user/register.js +++ b/Open-ILS/web/js/ui/default/actor/user/register.js @@ -1078,14 +1078,23 @@ function attachWidgetEvents(fmcls, fmfield, widget) { case 'day_phone': // if configured, use the last four digits of the day phone number as the password + // Alt, use the first capture group of the validator regex if(uEditUsePhonePw && patron.isnew()) { - dojo.connect(widget.widget, 'onChange', + dojo.connect(widget.widget, 'onChange', widget.widget, function(newVal) { - if(newVal && newVal.length >= 4) { + var newPw = false; + if(this.regExp) { + matches = RegExp(this.regExp).exec(newVal); + if(matches.length > 1) newPw = matches[1]; + } + if(!newPw && newVal && newVal.length >= 4) { + newPw = newVal.substring(newVal.length - 4); + } + if(newPw) { var pw1 = findWidget('au', 'passwd').widget; var pw2 = findWidget('au', 'passwd2').widget; - pw1.attr('value', newVal.substring(newVal.length - 4)); - pw2.attr('value', newVal.substring(newVal.length - 4)); + pw1.attr('value', newPw); + pw2.attr('value', newPw); } } );