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

(-)a/Koha/Validation.pm (+80 lines)
Line 0 Link Here
1
package Koha::Validation;
2
3
# Copyright 2017 Koha-Suomi Oy
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use C4::Context;
23
use Email::Valid;
24
25
=head1 NAME
26
27
Koha::Validation - validates inputs
28
29
=head1 SYNOPSIS
30
31
  use Koha::Validation
32
33
=head1 DESCRIPTION
34
35
This module lets you validate given inputs.
36
37
=head2 METHODS
38
39
=head3 email
40
41
Koha::Validation::email("email@address.com");
42
43
Validates given email.
44
45
returns: 1 if the given email is valid (or empty), 0 otherwise.
46
47
=cut
48
49
sub email {
50
    my $address = shift;
51
52
    return 1 unless $address;
53
    return 0 if $address =~ /(^(\s))|((\s)$)/;
54
55
    return (not defined Email::Valid->address($address)) ? 0:1;
56
}
57
58
=head3 phone
59
60
Koha::Validation::validate_phonenumber(123456789);
61
62
Validates given phone number.
63
64
returns: 1 if the given phone number is valid (or empty), 0 otherwise.
65
66
=cut
67
68
sub phone {
69
    my $phonenumber = shift;
70
71
    return 1 unless $phonenumber;
72
    return 0 if $phonenumber =~ /(^(\s))|((\s)$)/;
73
74
    my $regex = C4::Context->preference("ValidatePhoneNumber");
75
    $regex = qr/$regex/;
76
77
    return ($phonenumber !~ /$regex/) ? 0:1;
78
}
79
80
1;
(-)a/installer/data/mysql/atomicupdate/Bug_14620-Contact-information-validation.perl (+7 lines)
Line 0 Link Here
1
$DBversion = 'XXX';  # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do("INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES ('ValidatePhoneNumber','','','Regex for validation of patron phone numbers.','Textarea')");
4
5
    SetVersion( $DBversion );
6
    print "Upgrade to $DBversion done (Bug 14620 - description)\n";
7
}
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 663-668 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
663
('UseQueryParser','0',NULL,'If enabled, try to use QueryParser for queries.','YesNo'),
663
('UseQueryParser','0',NULL,'If enabled, try to use QueryParser for queries.','YesNo'),
664
('UseTransportCostMatrix','0','','Use Transport Cost Matrix when filling holds','YesNo'),
664
('UseTransportCostMatrix','0','','Use Transport Cost Matrix when filling holds','YesNo'),
665
('UseWYSIWYGinSystemPreferences','0','','Show WYSIWYG editor when editing certain HTML system preferences.','YesNo'),
665
('UseWYSIWYGinSystemPreferences','0','','Show WYSIWYG editor when editing certain HTML system preferences.','YesNo'),
666
('ValidatePhoneNumber','','','Regex for validation of patron phone numbers.','Textarea'),
666
('viewISBD','1','','Allow display of ISBD view of bibiographic records','YesNo'),
667
('viewISBD','1','','Allow display of ISBD view of bibiographic records','YesNo'),
667
('viewLabeledMARC','0','','Allow display of labeled MARC view of bibiographic records','YesNo'),
668
('viewLabeledMARC','0','','Allow display of labeled MARC view of bibiographic records','YesNo'),
668
('viewMARC','1','','Allow display of MARC view of bibiographic records','YesNo'),
669
('viewMARC','1','','Allow display of MARC view of bibiographic records','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+9 lines)
Lines 257-259 Patrons: Link Here
257
         - days and remove anonymized patron accounts after
257
         - days and remove anonymized patron accounts after
258
         - pref: PatronRemovalDelay
258
         - pref: PatronRemovalDelay
259
         - "days.<br>IMPORTANT: No action is performed when these delays are empty (no text). But a zero value ('0') is interpreted as no delay (do it now)! The actions are performed by the cleanup database cron job."
259
         - "days.<br>IMPORTANT: No action is performed when these delays are empty (no text). But a zero value ('0') is interpreted as no delay (do it now)! The actions are performed by the cleanup database cron job."
260
     -
261
         - Use the following regex /
262
         - pref: ValidatePhoneNumber
263
           type: textarea
264
           class: code
265
         - / to validate patrons' phone numbers.
266
         - Example ^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$
267
         - (Source of example <a href="http://regexlib.com/REDetails.aspx?regexp_id=3009">RegExLib.com</a>)
268
         - Leave blank to accept any phone number.
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (+24 lines)
Lines 127-132 Link Here
127
            [% END %]
127
            [% END %]
128
            [% IF ERROR_bad_email_alternative %]
128
            [% IF ERROR_bad_email_alternative %]
129
                <li id="ERROR_bad_email_alternative">The alternative email is invalid.</li>
129
                <li id="ERROR_bad_email_alternative">The alternative email is invalid.</li>
130
            [% END %]
131
            [% IF ERROR_bad_phone %]
132
                <li id="ERROR_bad_phone">The primary phone is invalid.</li>
133
            [% END %]
134
            [% IF ERROR_bad_phone_secondary %]
135
                <li id="ERROR_bad_phone_secondary">The secondary phone is invalid.</li>
136
            [% END %]
137
            [% IF ERROR_bad_phone_alternative %]
138
                <li id="ERROR_bad_phone_alternative">The alternative phone is invalid.</li>
139
            [% END %]
140
            [% IF ERROR_bad_smsnumber %]
141
                <li id="ERROR_bad_smsnumber">The SMS number is invalid.</li>
130
            [% END %]
142
            [% END %]
131
			</ul>
143
			</ul>
132
		</div>
144
		</div>
Lines 1317-1322 Link Here
1317
            });
1329
            });
1318
        });
1330
        });
1319
1331
1332
        var MSG_INCORRECT_PHONE = _("Please enter a valid phone number.");
1333
        $.validator.addMethod('phone', function(value) {
1334
            value = value.trim();
1335
            if (!value.trim()) {
1336
                return 1;
1337
            }
1338
            else {
1339
                return (value.match(/[% ValidatePhoneNumber %]/));
1340
            }
1341
        },
1342
        MSG_INCORRECT_PHONE);
1343
1320
        var MSG_SEPARATOR = _("Separator must be / in field %s");
1344
        var MSG_SEPARATOR = _("Separator must be / in field %s");
1321
        var MSG_INCORRECT_DAY = _("Invalid day entered in field %s");
1345
        var MSG_INCORRECT_DAY = _("Invalid day entered in field %s");
1322
        var MSG_INCORRECT_MONTH = _("Invalid month entered in field %s");
1346
        var MSG_INCORRECT_MONTH = _("Invalid month entered in field %s");
(-)a/koha-tmpl/intranet-tmpl/prog/js/members.js (+25 lines)
Lines 343-348 $(document).ready(function(){ Link Here
343
            password2: {
343
            password2: {
344
               password_match: true
344
               password_match: true
345
            },
345
            },
346
            phone: {
347
                phone: true
348
            },
349
            phonepro: {
350
                phone: true
351
            },
352
            B_phone: {
353
                phone: true
354
            },
355
            mobile: {
356
                phone: true
357
            },
346
            SMSnumber: {
358
            SMSnumber: {
347
               phone: true,
359
               phone: true,
348
            }
360
            }
Lines 353-362 $(document).ready(function(){ Link Here
353
                return false;
365
                return false;
354
            else
366
            else
355
                form.beenSubmitted = true;
367
                form.beenSubmitted = true;
368
                $("#email, #emailpro, #B_email").each(function(){
369
                    $(this).val($.trim($(this).val()));
370
                });
371
                $("#phone, #phonepro, #B_phone, #SMSnumber").each(function(){
372
                    $(this).val($.trim($(this).val()));
373
                });
356
                form.submit();
374
                form.submit();
357
            }
375
            }
358
    });
376
    });
359
377
378
    $("#email, #emailpro, #B_email").each(function(){
379
        $(this).val($.trim($(this).val()));
380
    });
381
    $("#phone, #phonepro, #B_phone, #SMSnumber").each(function(){
382
        $(this).val($.trim($(this).val()));
383
    });
384
360
    var mrform = $("#manual_restriction_form");
385
    var mrform = $("#manual_restriction_form");
361
    var mrlink = $("#add_manual_restriction");
386
    var mrlink = $("#add_manual_restriction");
362
    mrform.hide();
387
    mrform.hide();
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt (+37 lines)
Lines 80-85 Link Here
80
                                [% IF field == "email" %]<li>Contact information: <a href="#borrower_email">primary email address</a></li>[% END %]
80
                                [% IF field == "email" %]<li>Contact information: <a href="#borrower_email">primary email address</a></li>[% END %]
81
                                [% IF field == "emailpro" %]<li>Contact information: <a href="#borrower_emailpro">secondary email address</a></li>[% END %]
81
                                [% IF field == "emailpro" %]<li>Contact information: <a href="#borrower_emailpro">secondary email address</a></li>[% END %]
82
                                [% IF field == "B_email" %]<li>Alternate address information: <a href="#borrower_B_email">email address</a></li>[% END %]
82
                                [% IF field == "B_email" %]<li>Alternate address information: <a href="#borrower_B_email">email address</a></li>[% END %]
83
                                [% IF field == "phone" %]<li>Contact information: <a href="#borrower_phone">primary phone</a></li>[% END %]
84
                                [% IF field == "phonepro" %]<li>Contact information: <a href="#borrower_phonepro">secondary phone</a></li>[% END %]
85
                                [% IF field == "mobile" %]<li>Contact information: <a href="#borrower_mobile">other phone</a></li>[% END %]
86
                                [% IF field == "B_phone" %]<li>Alternate address information: <a href="#borrower_B_phone">phone</a></li>[% END %]
83
                                [% IF field == "password_match" %]<li>Passwords do not match! <a href="#password">password</a></li>[% END %]
87
                                [% IF field == "password_match" %]<li>Passwords do not match! <a href="#password">password</a></li>[% END %]
84
                                [% IF field == "password_too_short" %]
88
                                [% IF field == "password_too_short" %]
85
                                    <li>Password must be at least [% minPasswordLength | html %] characters long.</li>
89
                                    <li>Password must be at least [% minPasswordLength | html %] characters long.</li>
Lines 999-1004 Link Here
999
                $('label.required').removeClass('required');
1003
                $('label.required').removeClass('required');
1000
            [% END %]
1004
            [% END %]
1001
1005
1006
            var MSG_INCORRECT_PHONE = _("Please enter a valid phone number.");
1007
            $.validator.addMethod('phone', function(value) {
1008
                if (!value.trim()) {
1009
                    return 1;
1010
                }
1011
                else {
1012
                    return (value.match(/[% ValidatePhoneNumber %]/));
1013
                }
1014
            },
1015
            MSG_INCORRECT_PHONE);
1016
1002
            $("#memberentry-form").validate({
1017
            $("#memberentry-form").validate({
1003
                rules: {
1018
                rules: {
1004
                    borrower_email: {
1019
                    borrower_email: {
Lines 1010-1015 Link Here
1010
                    borrower_B_email: {
1025
                    borrower_B_email: {
1011
                        email: true
1026
                        email: true
1012
                    },
1027
                    },
1028
                    borrower_mobile: {
1029
                        phone: true
1030
                    },
1031
                    borrower_phone: {
1032
                        phone: true
1033
                    },
1034
                    borrower_phonepro: {
1035
                        phone: true
1036
                    },
1037
                    borrower_B_phone: {
1038
                        phone: true
1039
                    },
1013
                    borrower_password: {
1040
                    borrower_password: {
1014
                        [% IF mandatory.defined('password') %]
1041
                        [% IF mandatory.defined('password') %]
1015
                        required: true,
1042
                        required: true,
Lines 1033-1038 Link Here
1033
                    }
1060
                    }
1034
                    else {
1061
                    else {
1035
                        form.beenSubmitted = true;
1062
                        form.beenSubmitted = true;
1063
                        $("#borrower_email, #borrower_emailpro, #borrower_B_email").each(function(){
1064
                            $(this).val($.trim($(this).val()));
1065
                        });
1066
                        $("#borrower_phone, #borrower_phonepro, #borrower_B_phone").each(function(){
1067
                            $(this).val($.trim($(this).val()));
1068
                        });
1036
                        form.submit();
1069
                        form.submit();
1037
                    }
1070
                    }
1038
                },
1071
                },
Lines 1047-1052 Link Here
1047
                }
1080
                }
1048
            });
1081
            });
1049
1082
1083
            $("#borrower_email, #borrower_emailpro, #borrower_B_email, #borrower_phone, #borrower_phonepro, #borrower_B_phone").on("change", function(){
1084
                $(this).val($.trim($(this).val()));
1085
            });
1086
1050
            [% IF patron.guarantor_relationships && !Koha.Preference('OPACPrivacy') %]
1087
            [% IF patron.guarantor_relationships && !Koha.Preference('OPACPrivacy') %]
1051
1088
1052
                [% IF Koha.Preference('AllowPatronToSetCheckoutsVisibilityForGuarantor') %]
1089
                [% IF Koha.Preference('AllowPatronToSetCheckoutsVisibilityForGuarantor') %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt (+44 lines)
Lines 28-33 Link Here
28
                    [% IF ( settings_updated ) %]
28
                    [% IF ( settings_updated ) %]
29
                        <div class="alert alert-success"><h4>Settings updated</h4></div>
29
                        <div class="alert alert-success"><h4>Settings updated</h4></div>
30
                    [% END %]
30
                    [% END %]
31
                    [% IF ( invalid_smsnumber ) %]
32
                        <div class="alert alert-error"><h4>Invalid SMS number</h4></div>
33
                    [% END %]
31
                    <form action="/cgi-bin/koha/opac-messaging.pl" method="get" name="opacmessaging">
34
                    <form action="/cgi-bin/koha/opac-messaging.pl" method="get" name="opacmessaging">
32
                        <input type="hidden" name="modify" value="yes" />
35
                        <input type="hidden" name="modify" value="yes" />
33
36
Lines 182-187 Link Here
182
      }
185
      }
183
    });
186
    });
184
    $("#info_digests").tooltip();
187
    $("#info_digests").tooltip();
188
189
    var MSG_INCORRECT_PHONE = _("Please enter a valid phone number.");
190
    $.validator.addMethod('phone', function(value) {
191
        if (!value.trim()) {
192
            return 1;
193
        }
194
        else {
195
            return (value.match(/[% ValidatePhoneNumber %]/));
196
        }
197
    },
198
    MSG_INCORRECT_PHONE);
199
200
    $("form[name='opacmessaging']").validate({
201
        rules: {
202
            SMSnumber: {
203
                phone: true
204
            }
205
        },
206
        submitHandler: function(form) {
207
            $("body, form input[type='submit'], form button[type='submit'], form a").addClass('waiting');
208
            if (form.beenSubmitted) {
209
                return false;
210
            }
211
            else {
212
                form.beenSubmitted = true;
213
                $("#SMSnumber").each(function(){
214
                    $(this).val($.trim($(this).val()));
215
                });
216
                form.submit();
217
            }
218
        },
219
        errorPlacement: function(error, element) {
220
            error.insertAfter(element.closest("li")).wrap('<li></li>');
221
            error.addClass('alert-error');
222
            error.width("auto");
223
        }
224
    });
225
    $("#SMSnumber").on("change", function(){
226
        $(this).val($.trim($(this).val()));
227
    });
185
  });
228
  });
186
229
187
function normalizeSMS(value){
230
function normalizeSMS(value){
Lines 207-210 sms_input.addEventListener('paste', function(event) { Link Here
207
250
208
//]]>
251
//]]>
209
</script>
252
</script>
253
<script type="text/javascript" src="/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.validate.min.js"></script>
210
[% END %]
254
[% END %]
(-)a/members/memberentry.pl (-15 / +17 lines)
Lines 47-54 use Koha::Patron::Categories; Link Here
47
use Koha::Patron::HouseboundRole;
47
use Koha::Patron::HouseboundRole;
48
use Koha::Patron::HouseboundRoles;
48
use Koha::Patron::HouseboundRoles;
49
use Koha::Token;
49
use Koha::Token;
50
use Email::Valid;
51
use Koha::SMS::Providers;
50
use Koha::SMS::Providers;
51
use Koha::Validation;
52
52
53
use vars qw($debug);
53
use vars qw($debug);
54
54
Lines 371-389 if ($op eq 'save' || $op eq 'insert'){ Link Here
371
  }
371
  }
372
372
373
  # Validate emails
373
  # Validate emails
374
  my $emailprimary = $input->param('email');
374
  push (@errors, "ERROR_bad_email") if ($input->param('email') && !Koha::Validation::email($input->param('email')));
375
  my $emailsecondary = $input->param('emailpro');
375
  push (@errors, "ERROR_bad_email_secondary") if ($input->param('emailpro') && !Koha::Validation::email($input->param('emailpro')));
376
  my $emailalt = $input->param('B_email');
376
  push (@errors, "ERROR_bad_email_alternative") if ($input->param('B_email') && !Koha::Validation::email($input->param('B_email')));
377
377
  # Validate phone numbers
378
  if ($emailprimary) {
378
  push (@errors, "ERROR_bad_phone") if ($input->param('phone') && !Koha::Validation::phone($input->param('phone')));
379
      push (@errors, "ERROR_bad_email") if (!Email::Valid->address($emailprimary));
379
  push (@errors, "ERROR_bad_phone_secondary") if ($input->param('phonepro') && !Koha::Validation::phone($input->param('phonepro')));
380
  }
380
  push (@errors, "ERROR_bad_phone_alternative") if ($input->param('B_phone') && !Koha::Validation::phone($input->param('B_phone')));
381
  if ($emailsecondary) {
382
      push (@errors, "ERROR_bad_email_secondary") if (!Email::Valid->address($emailsecondary));
383
  }
384
  if ($emailalt) {
385
      push (@errors, "ERROR_bad_email_alternative") if (!Email::Valid->address($emailalt));
386
  }
387
381
388
  if (C4::Context->preference('ExtendedPatronAttributes')) {
382
  if (C4::Context->preference('ExtendedPatronAttributes')) {
389
    $extended_patron_attributes = parse_extended_patron_attributes($input);
383
    $extended_patron_attributes = parse_extended_patron_attributes($input);
Lines 411-417 if ( ($op eq 'modify' || $op eq 'insert' || $op eq 'save'|| $op eq 'duplicate') Link Here
411
# BZ 14683: Do not mixup mobile [read: other phone] with smsalertnumber
405
# BZ 14683: Do not mixup mobile [read: other phone] with smsalertnumber
412
my $sms = $input->param('SMSnumber');
406
my $sms = $input->param('SMSnumber');
413
if ( defined $sms ) {
407
if ( defined $sms ) {
414
    $newdata{smsalertnumber} = $sms;
408
    if (Koha::Validation::phone($sms)){
409
        $newdata{smsalertnumber} = $sms;
410
    } else {
411
        push (@errors, "ERROR_bad_smsnumber");
412
    }
415
}
413
}
416
414
417
###  Error checks should happen before this line.
415
###  Error checks should happen before this line.
Lines 746-751 if (C4::Context->preference('ExtendedPatronAttributes')) { Link Here
746
    patron_attributes_form($template, $borrowernumber, $op);
744
    patron_attributes_form($template, $borrowernumber, $op);
747
}
745
}
748
746
747
$template->param(
748
    ValidatePhoneNumber  => C4::Context->preference('ValidatePhoneNumber') || '.*',
749
);
750
749
if (C4::Context->preference('EnhancedMessagingPreferences')) {
751
if (C4::Context->preference('EnhancedMessagingPreferences')) {
750
    if ($op eq 'add') {
752
    if ($op eq 'add') {
751
        C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode }, $template);
753
        C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode }, $template);
(-)a/opac/opac-memberentry.pl (-4 / +17 lines)
Lines 34-40 use Koha::Patron::Consent; Link Here
34
use Koha::Patron::Modification;
34
use Koha::Patron::Modification;
35
use Koha::Patron::Modifications;
35
use Koha::Patron::Modifications;
36
use C4::Scrubber;
36
use C4::Scrubber;
37
use Email::Valid;
38
use Koha::DateUtils;
37
use Koha::DateUtils;
39
use Koha::Libraries;
38
use Koha::Libraries;
40
use Koha::Patron::Attribute::Types;
39
use Koha::Patron::Attribute::Types;
Lines 44-49 use Koha::Patron::Modification; Link Here
44
use Koha::Patron::Modifications;
43
use Koha::Patron::Modifications;
45
use Koha::Patrons;
44
use Koha::Patrons;
46
use Koha::Token;
45
use Koha::Token;
46
use Koha::Validation;
47
47
48
my $cgi = new CGI;
48
my $cgi = new CGI;
49
my $dbh = C4::Context->dbh;
49
my $dbh = C4::Context->dbh;
Lines 93-98 $template->param( Link Here
93
    mandatory         => $mandatory,
93
    mandatory         => $mandatory,
94
    libraries         => \@libraries,
94
    libraries         => \@libraries,
95
    OPACPatronDetails => C4::Context->preference('OPACPatronDetails'),
95
    OPACPatronDetails => C4::Context->preference('OPACPatronDetails'),
96
    ValidatePhoneNumber   => C4::Context->preference('ValidatePhoneNumber') || '.*',
96
);
97
);
97
98
98
my $attributes = ParsePatronAttributes($borrowernumber,$cgi);
99
my $attributes = ParsePatronAttributes($borrowernumber,$cgi);
Lines 408-414 sub CheckForInvalidFields { Link Here
408
    my $borrower = shift;
409
    my $borrower = shift;
409
    my @invalidFields;
410
    my @invalidFields;
410
    if ($borrower->{'email'}) {
411
    if ($borrower->{'email'}) {
411
        unless ( Email::Valid->address($borrower->{'email'}) ) {
412
        unless ( Koha::Validation::email($borrower->{'email'}) ) {
412
            push(@invalidFields, "email");
413
            push(@invalidFields, "email");
413
        } elsif ( C4::Context->preference("PatronSelfRegistrationEmailMustBeUnique") ) {
414
        } elsif ( C4::Context->preference("PatronSelfRegistrationEmailMustBeUnique") ) {
414
            my $patrons_with_same_email = Koha::Patrons->search( # FIXME Should be search_limited?
415
            my $patrons_with_same_email = Koha::Patrons->search( # FIXME Should be search_limited?
Lines 428-437 sub CheckForInvalidFields { Link Here
428
        }
429
        }
429
    }
430
    }
430
    if ($borrower->{'emailpro'}) {
431
    if ($borrower->{'emailpro'}) {
431
        push(@invalidFields, "emailpro") if (!Email::Valid->address($borrower->{'emailpro'}));
432
        push(@invalidFields, "emailpro") if (!Koha::Validation::email($borrower->{'emailpro'}));
432
    }
433
    }
433
    if ($borrower->{'B_email'}) {
434
    if ($borrower->{'B_email'}) {
434
        push(@invalidFields, "B_email") if (!Email::Valid->address($borrower->{'B_email'}));
435
        push(@invalidFields, "B_email") if (!Koha::Validation::email($borrower->{'B_email'}));
436
    }
437
    if ($borrower->{'mobile'}) {
438
        push(@invalidFields, "mobile") if (!Koha::Validation::phone($borrower->{'mobile'}));
439
    }
440
    if ($borrower->{'phone'}) {
441
        push(@invalidFields, "phone") if (!Koha::Validation::phone($borrower->{'phone'}));
442
    }
443
    if ($borrower->{'phonepro'}) {
444
        push(@invalidFields, "phonepro") if (!Koha::Validation::phone($borrower->{'phonepro'}));
445
    }
446
    if ($borrower->{'B_phone'}) {
447
        push(@invalidFields, "B_phone") if (!Koha::Validation::phone($borrower->{'B_phone'}));
435
    }
448
    }
436
    if ( defined $borrower->{'password'}
449
    if ( defined $borrower->{'password'}
437
        and $borrower->{'password'} ne $borrower->{'password2'} )
450
        and $borrower->{'password'} ne $borrower->{'password2'} )
(-)a/opac/opac-messaging.pl (-1 / +12 lines)
Lines 31-36 use C4::Members::Messaging; Link Here
31
use C4::Form::MessagingPreferences;
31
use C4::Form::MessagingPreferences;
32
use Koha::Patrons;
32
use Koha::Patrons;
33
use Koha::SMS::Providers;
33
use Koha::SMS::Providers;
34
use Koha::Validation;
34
35
35
my $query = CGI->new();
36
my $query = CGI->new();
36
37
Lines 54-63 my $patron = Koha::Patrons->find( $borrowernumber ); # FIXME and if borrowernumb Link Here
54
55
55
my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
56
my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
56
57
58
my $validate_phone = C4::Context->preference('ValidatePhoneNumber');
59
60
$template->param(
61
    ValidatePhoneNumber    => $validate_phone || '.*',
62
);
63
57
if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) {
64
if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) {
58
    my $sms = $query->param('SMSnumber');
65
    my $sms = $query->param('SMSnumber');
59
    my $sms_provider_id = $query->param('sms_provider_id');
66
    my $sms_provider_id = $query->param('sms_provider_id');
60
    if ( defined $sms && ( $patron->smsalertnumber // '' ) ne $sms
67
68
    my $valid_sms = Koha::Validation::phone($sms);
69
    $template->param( invalid_smsnumber => 1 ) unless $valid_sms;
70
71
    if ( defined $sms && $valid_sms && ( $patron->smsalertnumber // '' ) ne $sms
61
            or ( $patron->sms_provider_id // '' ) ne $sms_provider_id ) {
72
            or ( $patron->sms_provider_id // '' ) ne $sms_provider_id ) {
62
        $patron->set({
73
        $patron->set({
63
            smsalertnumber  => $sms,
74
            smsalertnumber  => $sms,
(-)a/t/db_dependent/Koha/Validation.t (-1 / +76 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# Copyright 2017 Koha-Suomi Oy
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Test::More tests => 3;
23
24
use t::lib::Mocks;
25
26
BEGIN {
27
    use_ok('Koha::Validation');
28
}
29
30
subtest 'email() tests' => sub {
31
    plan tests => 2;
32
33
    is(Koha::Validation::email('test'), 0, "'test' is invalid e-mail address'");
34
    is(Koha::Validation::email('test@example.com'), 1, '\'test@example.com\' is '
35
                               .'valid e-mail address');
36
};
37
38
subtest 'phone() tests' => sub {
39
    plan tests => 3;
40
41
    t::lib::Mocks::mock_preference('ValidatePhoneNumber', '');
42
43
    is(Koha::Validation::phone('test'), 1, 'Phone number validation is switched '
44
       .'off, so \'test\' is a valid phone number');
45
46
    # An example: Finnish Phone number validation regex
47
    subtest 'Finnish phone number validation regex' => sub {
48
        t::lib::Mocks::mock_preference('ValidatePhoneNumber',
49
            '^((90[0-9]{3})?0|\+358\s?)(?!(100|20(0|2(0|[2-3])|9[8-9])|300|600|70'
50
           .'0|708|75(00[0-3]|(1|2)\d{2}|30[0-2]|32[0-2]|75[0-2]|98[0-2])))(4|50|'
51
           .'10[1-9]|20(1|2(1|[4-9])|[3-9])|29|30[1-9]|71|73|75(00[3-9]|30[3-9]|3'
52
           .'2[3-9]|53[3-9]|83[3-9])|2|3|5|6|8|9|1[3-9])\s?(\d\s?){4,19}\d$'
53
        );
54
55
        is(Koha::Validation::phone('1234'), 0, '1234 is invalid phone number.');
56
        is(Koha::Validation::phone('+358501234567'), 1, '+358501234567 is valid '
57
           .'phone number.');
58
        is(Koha::Validation::phone('+1-202-555-0198'), 0, '+1-202-555-0198 is '
59
          .'invalid phone number.');
60
    };
61
62
    subtest 'International phone number validation regex' => sub {
63
        t::lib::Mocks::mock_preference('ValidatePhoneNumber',
64
            '^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]'
65
           .'{1,12}){1,2}$'
66
        );
67
68
        is(Koha::Validation::phone('nope'), 0, 'nope is invalid phone number.');
69
        is(Koha::Validation::phone('1234'), 1, '1234 is valid phone number.');
70
        is(Koha::Validation::phone('+358501234567'), 1, '+358501234567 is valid '
71
           .'phone number.');
72
        is(Koha::Validation::phone('+1-202-555-0198'), 1, '+1-202-555-0198 is '
73
          .'valid phone number.');
74
    };
75
76
};

Return to bug 14620