Skip to content

Commit 25b5f9e

Browse files
committed
bug fixes...
1 parent a24452b commit 25b5f9e

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

jquery.formvalidator.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/*
2-
*
32
* FORM VALIDATION MADE EASY
43
* ------------------------------------------
54
* Created by Victor Jonsson <http://www.victorjonsson.se>
@@ -9,8 +8,7 @@
98
* (c) 2011 Victor Jonsson, Sweden.
109
* Dual licensed under the MIT or GPL Version 2 licenses
1110
*
12-
* $version 1.2 beta
13-
*
11+
* $version 1.2
1412
*/
1513

1614
(function($) {
@@ -368,7 +366,7 @@ jQueryFormUtils.validateSwedishMobileNumber = function(number) {
368366
* @return {Boolean}
369367
*/
370368
jQueryFormUtils.validateBirthdate = function(val, dateFormat) {
371-
var inputDate = this.validateDate(val, dateFormat);
369+
var inputDate = this.parseDate(val, dateFormat);
372370
if (!inputDate)
373371
return false;
374372

@@ -392,29 +390,28 @@ jQueryFormUtils.validateBirthdate = function(val, dateFormat) {
392390
};
393391

394392
/**
395-
* Is it a correct date YYYY-MM-DD. Will return false if not, otherwise
393+
* Is it a correct date according to given dateFormat. Will return false if not, otherwise
396394
* an array 0=>year 1=>month 2=>day
397395
* @param {String} val
396+
* @param {String} dateFormat
398397
* @return {Array}|{Boolean}
399398
*/
400-
jQueryFormUtils.validateDate = function(val, dateFormat) {
399+
jQueryFormUtils.parseDate = function(val, dateFormat) {
401400
var divider = dateFormat.replace(/[a-zA-Z]/gi, '').substring(0,1);
402401
var regexp = '^';
403402
var formatParts = dateFormat.split(divider);
404403
for(var i=0; i < formatParts.length; i++)
405404
regexp += (i > 0 ? '\\'+divider:'') + '(\\d{'+formatParts[i].length+'})';
406405
regexp += '$';
407-
406+
408407
var matches = val.match(new RegExp(regexp));
409-
410-
// enklast m�jliga...
411408
if (matches == null)
412409
return false;
413410

414411
var findDateUnit = function(unit, formatParts, matches) {
415412
for(var i=0; i < formatParts.length; i++) {
416413
if(formatParts[i].substring(0,1) == unit) {
417-
return matches[i+1];
414+
return jQueryFormUtils.parseDateInt(matches[i+1]);
418415
}
419416
}
420417
return -1;
@@ -423,10 +420,7 @@ jQueryFormUtils.validateDate = function(val, dateFormat) {
423420
var month = findDateUnit('m', formatParts, matches);
424421
var day = findDateUnit('d', formatParts, matches);
425422
var year = findDateUnit('y', formatParts, matches);
426-
month = jQueryFormUtils.parseDateInt(month);
427-
day = jQueryFormUtils.parseDateInt(day);
428-
year = jQueryFormUtils.parseDateInt(year);
429-
423+
430424
if (month == 2 && day > 28 || month > 12 || month == 0)
431425
return false;
432426
if ((this.isShortMonth(month) && day > 30) || (!this.isShortMonth(month) && day > 31) || day == 0)
@@ -675,7 +669,7 @@ jQueryFormUtils.validateInput = function(el, language, config, form) {
675669
}
676670

677671
// Date
678-
else if (validationRules.indexOf('validate_date') > -1 && !jQueryFormUtils.validateDate(value, config.dateFormat)) {
672+
else if (validationRules.indexOf('validate_date') > -1 && !jQueryFormUtils.parseDate(value, config.dateFormat)) {
679673
return language.badDate;
680674
}
681675

0 commit comments

Comments
 (0)