Regex check for "last 4 digits of phone number"
authorThomas Berezansky <tsbere@mvlc.org>
Mon, 13 Jun 2011 05:01:52 +0000 (01:01 -0400)
committerJason Etheridge <jason@esilibrary.com>
Thu, 8 Sep 2011 05:21:38 +0000 (01:21 -0400)
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 <tsbere@mvlc.org>
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/web/js/ui/default/actor/user/register.js

index ac9b45c..3fe41b8 100644 (file)
@@ -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);
                             }
                         }
                     );