View | Details | Raw Unified | Return to bug 14620
Collapse All | Expand All

(-)a/Koha/Validation.pm (-4 / +2 lines)
Lines 53-58 sub validate_email { Link Here
53
    
53
    
54
    # make sure we are allowed to validate emails
54
    # make sure we are allowed to validate emails
55
    return 1 if not C4::Context->preference("ValidateEmailAddress");
55
    return 1 if not C4::Context->preference("ValidateEmailAddress");
56
    return 0 if $address =~ /(^(\s))|((\s)$)/;
56
    return 0 if not defined $address;
57
    return 0 if not defined $address;
57
    return (not defined Email::Valid->address($address)) ? 0:1; 
58
    return (not defined Email::Valid->address($address)) ? 0:1; 
58
}
59
}
Lines 70-84 returns: 1 if the given phone number is valid, 0 otherwise. Link Here
70
sub validate_phonenumber {
71
sub validate_phonenumber {
71
    my $phonenumber = shift;
72
    my $phonenumber = shift;
72
    
73
    
73
    $phonenumber =~ s/\s+//g;
74
    
75
    # make sure we are allowed to validate phone numbers
74
    # make sure we are allowed to validate phone numbers
76
    return 1 if C4::Context->preference("ValidatePhoneNumber") eq "OFF";
75
    return 1 if C4::Context->preference("ValidatePhoneNumber") eq "OFF";
77
    return 1 if $phonenumber eq "";
76
    return 1 if $phonenumber eq "";
78
    return 0 if not defined $phonenumber;
77
    return 0 if not defined $phonenumber;
79
    
78
    
80
    my $regex = get_phonenumber_regex(C4::Context->preference("ValidatePhoneNumber"));
79
    my $regex = get_phonenumber_regex(C4::Context->preference("ValidatePhoneNumber"));
81
    #die $regex;
82
    return ($phonenumber !~ /$regex/) ? 0:1;
80
    return ($phonenumber !~ /$regex/) ? 0:1;
83
}
81
}
84
82
Lines 100-106 sub get_phonenumber_regex { Link Here
100
        return qr/^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$/;
98
        return qr/^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$/;
101
    }
99
    }
102
    elsif (C4::Context->preference("ValidatePhoneNumber") eq "fin") {
100
    elsif (C4::Context->preference("ValidatePhoneNumber") eq "fin") {
103
        return qr/^((90[0-9]{3})?0|\+358\s?)(?!(100|20(0|2(0|[2-3])|9[8-9])|300|600|700|708|75(00[0-3]|(1|2)\d{2}|30[0-2]|32[0-2]|75[0-2]|98[0-2])))(4|50|10[1-9]|20(1|2(1|[4-9])|[3-9])|29|30[1-9]|71|73|75(00[3-9]|30[3-9]|32[3-9]|53[3-9]|83[3-9])|2|3|5|6|8|9|1[3-9])\s?(\d\s?){4,20}$/;
101
        return qr/^((90[0-9]{3})?0|\+358\s?)(?!(100|20(0|2(0|[2-3])|9[8-9])|300|600|700|708|75(00[0-3]|(1|2)\d{2}|30[0-2]|32[0-2]|75[0-2]|98[0-2])))(4|50|10[1-9]|20(1|2(1|[4-9])|[3-9])|29|30[1-9]|71|73|75(00[3-9]|30[3-9]|32[3-9]|53[3-9]|83[3-9])|2|3|5|6|8|9|1[3-9])\s?(\d\s?){4,19}\d$/;
104
    }
102
    }
105
    
103
    
106
    return "";
104
    return "";
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-5 / +27 lines)
Lines 37-43 Link Here
37
        
37
        
38
        var MSG_INCORRECT_PHONE = _("Please enter a valid phone number.");
38
        var MSG_INCORRECT_PHONE = _("Please enter a valid phone number.");
39
        $.validator.addMethod('phone', function(value) {
39
        $.validator.addMethod('phone', function(value) {
40
            value = value.trim();
41
            if (!value.trim()) {
40
            if (!value.trim()) {
42
                return 1;
41
                return 1;
43
            }
42
            }
Lines 82-90 Link Here
82
                $("body, form input[type='submit'], form button[type='submit'], form a").addClass('waiting');
81
                $("body, form input[type='submit'], form button[type='submit'], form a").addClass('waiting');
83
                if (form.beenSubmitted)
82
                if (form.beenSubmitted)
84
                    return false;
83
                    return false;
85
                else
84
                else {
86
                    form.beenSubmitted = true;
85
                        form.beenSubmitted = true;
87
                    form.submit();
86
                        [% IF ValidateEmailAddress %]
87
                        $("#email, #emailpro, #B_email").each(function(){
88
                            $(this).val($.trim($(this).val()));
89
                        });
90
                        [% END %]
91
                        [% IF ValidatePhoneNumber %]
92
                        $("#phone, #phonepro, #B_phone, #SMSnumber").each(function(){
93
                            $(this).val($.trim($(this).val()));
94
                        });
95
                        [% END %]
96
                        form.submit();
97
                    }
88
                }
98
                }
89
        });
99
        });
90
100
Lines 95-100 Link Here
95
            $("#email").on("input", function(){
105
            $("#email").on("input", function(){
96
                disableCheckboxesWithInvalidPreferences($(this), "email");
106
                disableCheckboxesWithInvalidPreferences($(this), "email");
97
            });
107
            });
108
            $("#email, #emailpro, #B_email").on("change, click", function(){
109
                $(this).val($.trim($(this).val()));
110
                disableCheckboxesWithInvalidPreferences($(this), "email");
111
            });
98
        [% END %]
112
        [% END %]
99
        
113
        
100
        [% IF ValidatePhoneNumber %]
114
        [% IF ValidatePhoneNumber %]
Lines 105-115 Link Here
105
                disableCheckboxesWithInvalidPreferences($("#phone"), "phone");
119
                disableCheckboxesWithInvalidPreferences($("#phone"), "phone");
106
            [% END %]
120
            [% END %]
107
            $("#SMSnumber").on("input", function(){
121
            $("#SMSnumber").on("input", function(){
108
            disableCheckboxesWithInvalidPreferences($(this), "sms");
122
                disableCheckboxesWithInvalidPreferences($(this), "sms");
123
            });
124
            $("#SMSnumber").on("change, click", function(){
125
                $(this).val($.trim($(this).val()));
126
                disableCheckboxesWithInvalidPreferences($(this), "sms");
109
            });
127
            });
110
            $("#phone").on("input", function(){
128
            $("#phone").on("input", function(){
111
                disableCheckboxesWithInvalidPreferences($(this), "phone");
129
                disableCheckboxesWithInvalidPreferences($(this), "phone");
112
            });
130
            });
131
            $("#phone, #phonepro, #B_phone").on("change, click", function(){
132
                $(this).val($.trim($(this).val()));
133
                disableCheckboxesWithInvalidPreferences($(this), "phone");
134
            });
113
        [% END %]
135
        [% END %]
114
        
136
        
115
        var mrform = $("#manual_restriction_form");
137
        var mrform = $("#manual_restriction_form");
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt (+16 lines)
Lines 870-875 Link Here
870
                    }
870
                    }
871
                    else {
871
                    else {
872
                        form.beenSubmitted = true;
872
                        form.beenSubmitted = true;
873
                        [% IF ValidateEmailAddress %]
874
                        $("#borrower_email, #borrower_emailpro, #borrower_B_email").each(function(){
875
                            $(this).val($.trim($(this).val()));
876
                        });
877
                        [% END %]
878
                        [% IF ValidatePhoneNumber %]
879
                        $("#borrower_phone, #borrower_phonepro, #borrower_B_phone, #SMSnumber").each(function(){
880
                            $(this).val($.trim($(this).val()));
881
                        });
882
                        [% END %]
873
                        form.submit();
883
                        form.submit();
874
                    }
884
                    }
875
                },
885
                },
Lines 883-888 Link Here
883
                    error.css('width', 'auto');
893
                    error.css('width', 'auto');
884
                }
894
                }
885
            });
895
            });
896
            $("#borrower_email, #borrower_emailpro, #borrower_B_email").on("change, click", function(){
897
                $(this).val($.trim($(this).val()));
898
            });
899
            $("#borrower_phone, #borrower_phonepro, #borrower_B_phone").on("change, click", function(){
900
                $(this).val($.trim($(this).val()));
901
            });
886
        });
902
        });
887
    //]]>
903
    //]]>
888
    </script>
904
    </script>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt (-1 / +9 lines)
Lines 182-187 Link Here
182
            }
182
            }
183
            else {
183
            else {
184
                form.beenSubmitted = true;
184
                form.beenSubmitted = true;
185
                [% IF ValidatePhoneNumber %]
186
                    $("#SMSnumber").each(function(){
187
                        $(this).val($.trim($(this).val()));
188
                    });
189
                [% END %]
185
                form.submit();
190
                form.submit();
186
            }
191
            }
187
        },
192
        },
Lines 212-217 Link Here
212
        $("#SMSnumber").on("input", function(){
217
        $("#SMSnumber").on("input", function(){
213
            disableCheckboxesWithInvalidPreferences($(this), "sms");
218
            disableCheckboxesWithInvalidPreferences($(this), "sms");
214
        });
219
        });
220
        $("#SMSnumber").on("change, click", function(){
221
            $(this).val($.trim($(this).val()));
222
            disableCheckboxesWithInvalidPreferences($(this), "sms");
223
        });
215
    [% END %]
224
    [% END %]
216
  });
225
  });
217
//]]>
226
//]]>
218
- 

Return to bug 14620