From dc7d1095af36b2d0422f8e63d7021b5caa287230 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Thu, 13 Aug 2015 15:25:06 +0300 Subject: [PATCH] Bug 14620 - Whitespace fix for validations This fix trims emails and phone numbers just before form is sent. --- Koha/Validation.pm | 6 ++---- .../prog/en/modules/members/memberentrygen.tt | 23 ++++++++++++++++++++++ .../bootstrap/en/modules/opac-memberentry.tt | 16 +++++++++++++++ .../bootstrap/en/modules/opac-messaging.tt | 11 +++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Koha/Validation.pm b/Koha/Validation.pm index 90f1ef0..e952319 100644 --- a/Koha/Validation.pm +++ b/Koha/Validation.pm @@ -53,6 +53,7 @@ sub validate_email { # make sure we are allowed to validate emails return 1 if not C4::Context->preference("ValidateEmailAddress"); + return 0 if $address =~ /(^(\s))|((\s)$)/; return 0 if not defined $address; return (not defined Email::Valid->address($address)) ? 0:1; } @@ -70,15 +71,12 @@ returns: 1 if the given phone number is valid, 0 otherwise. sub validate_phonenumber { my $phonenumber = shift; - $phonenumber =~ s/\s+//g; - # make sure we are allowed to validate phone numbers return 1 if C4::Context->preference("ValidatePhoneNumber") eq "OFF"; return 1 if $phonenumber eq ""; return 0 if not defined $phonenumber; my $regex = get_phonenumber_regex(C4::Context->preference("ValidatePhoneNumber")); - #die $regex; return ($phonenumber !~ /$regex/) ? 0:1; } @@ -100,7 +98,7 @@ sub get_phonenumber_regex { return qr/^((\+)?[1-9]{1,2})?([-\s\.])?((\(\d{1,4}\))|\d{1,4})(([-\s\.])?[0-9]{1,12}){1,2}$/; } elsif (C4::Context->preference("ValidatePhoneNumber") eq "fin") { - 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}$/; + 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$/; } return ""; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 350e4ad..eb5550b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -84,10 +84,33 @@ return false; else form.beenSubmitted = true; + [% IF ValidateEmailAddress %] + $("#email, #emailpro, #B_email").each(function(){ + $(this).val($.trim($(this).val())); + }); + [% END %] + [% IF ValidatePhoneNumber %] + $("#phone, #phonepro, #B_phone, #SMSnumber").each(function(){ + $(this).val($.trim($(this).val())); + }); + [% END %] form.submit(); } }); + [% IF ValidateEmailAddress %] + $("#email, #emailpro, #B_email").on("change, click", function(){ + $(this).val($.trim($(this).val())); + }); + [% END %] + [% IF ValidatePhoneNumber %] + $("#SMSnumber").on("change, click", function(){ + $(this).val($.trim($(this).val())); + }); + $("#phone, #phonepro, #B_phone").on("change, click", function(){ + $(this).val($.trim($(this).val())); + }); + [% END %] var mrform = $("#manual_restriction_form"); var mrlink = $("#add_manual_restriction"); mrform.hide(); diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt index d08f9d2..744eb7f 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt @@ -870,6 +870,16 @@ } else { form.beenSubmitted = true; + [% IF ValidateEmailAddress %] + $("#borrower_email, #borrower_emailpro, #borrower_B_email").each(function(){ + $(this).val($.trim($(this).val())); + }); + [% END %] + [% IF ValidatePhoneNumber %] + $("#borrower_phone, #borrower_phonepro, #borrower_B_phone, #SMSnumber").each(function(){ + $(this).val($.trim($(this).val())); + }); + [% END %] form.submit(); } }, @@ -883,6 +893,12 @@ error.css('width', 'auto'); } }); + $("#borrower_email, #borrower_emailpro, #borrower_B_email").on("change, click", function(){ + $(this).val($.trim($(this).val())); + }); + $("#borrower_phone, #borrower_phonepro, #borrower_B_phone").on("change, click", function(){ + $(this).val($.trim($(this).val())); + }); }); //]]> diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt index 1656854..fccb0e1 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt @@ -179,6 +179,11 @@ } else { form.beenSubmitted = true; + [% IF ValidatePhoneNumber %] + $("#SMSnumber").each(function(){ + $(this).val($.trim($(this).val())); + }); + [% END %] form.submit(); } }, @@ -192,6 +197,12 @@ error.css('width', 'auto'); } }); + + [% IF ( ValidatePhoneNumber ) %] + $("#SMSnumber").on("change, click", function(){ + $(this).val($.trim($(this).val())); + }); + [% END %] }); //]]> -- 1.9.1