Last active
August 29, 2015 14:07
-
-
Save maxxscho/c1bb9da098f982bd92cd to your computer and use it in GitHub Desktop.
jQuery Validate additional validation for dates in the format dd.mm.yyyy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Additional method for jquery validate | |
Valiate dates in the format dd.mm.yyyy | |
------------------------------------- */ | |
jQuery.validator.addMethod( | |
"dateDECH", | |
function(value, element) { | |
var check = false; | |
var re = /^\d{1,2}\.\d{1,2}\.\d{4}$/; | |
if( re.test(value)){ | |
var adata = value.split('.'); | |
var dd = parseInt(adata[0],10); | |
var mm = parseInt(adata[1],10); | |
var yyyy = parseInt(adata[2],10); | |
var xdata = new Date(yyyy,mm-1,dd); | |
if ( ( xdata.getFullYear() === yyyy ) && ( xdata.getMonth () === mm - 1 ) && ( xdata.getDate() === dd ) ) { | |
check = true; | |
} | |
else { | |
check = false; | |
} | |
} else { | |
check = false; | |
} | |
return this.optional(element) || check; | |
}, | |
"Geben Sie bitte ein korrektes Datum ein!" | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment