Bug 14060: Improve regex to limit year to 4 integers

01/01/01984 should not be considered as a valid date.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit eab75d0aa4)
Signed-off-by: Frédéric Demians <f.demians@tamil.fr>
This commit is contained in:
Jonathan Druart 2016-09-06 12:58:31 +01:00 committed by Frédéric Demians
parent ee073f0086
commit 4f5d1faef5
1 changed files with 4 additions and 4 deletions

View File

@ -14,16 +14,16 @@ function is_valid_date(date) {
var dateformat = dateformat_str = '[% Koha.Preference('dateformat') %]';
if ( dateformat == 'us' ) {
if ( date.search(/\d{2}\/\d{2}\/\d{4}/) == -1 ) return 0;
if ( date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1 ) return 0;
dateformat = 'mm/dd/yy';
} else if ( dateformat == 'metric' ) {
if ( date.search(/\d{2}\/\d{2}\/\d{4}/) == -1 ) return 0;
if ( date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1 ) return 0;
dateformat = 'dd/mm/yy';
} else if (dateformat == 'iso' ) {
if ( date.search(/\d{2}-\d{2}-\d{4}/) == -1 ) return 0;
if ( date.search(/^\d{2}-\d{2}-\d{4}($|\s)/) == -1 ) return 0;
dateformat = 'yy-mm-dd';
} else if ( dateformat == 'dmydot' ) {
if ( date.search(/\d{2}\.\d{2}\.\d{4}/) == -1 ) return 0;
if ( date.search(/^\d{2}\.\d{2}\.\d{4}($|\s)/) == -1 ) return 0;
dateformat = 'dd.mm.yy';
}
try {