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)
committerThomas Berezansky <tsbere@mvlc.org>
Tue, 2 Aug 2011 17:55:13 +0000 (13:55 -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>
Open-ILS/web/js/ui/default/actor/user/register.js

index be1c111..65e4a13 100644 (file)
@@ -1073,14 +1073,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);
                             }
                         }
                     );