Posted By

tuuul on 08/21/11


Tagged

date jquery validation german addMethod


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

spee66


jQuery validation additional method german date


 / Published in: jQuery
 

An additional method for the jQuery validation plugin to validate a german date (dd.mm.YYYY) based on DateITA method.

  1. jQuery.validator.addMethod(
  2. "dateDECH",
  3. function(value, element) {
  4. var check = false;
  5. var re = /^\d{1,2}\.\d{1,2}\.\d{4}$/;
  6. if( re.test(value)){
  7. var adata = value.split('.');
  8. var dd = parseInt(adata[0],10);
  9. var mm = parseInt(adata[1],10);
  10. var yyyy = parseInt(adata[2],10);
  11. var xdata = new Date(yyyy,mm-1,dd);
  12. if ( ( xdata.getFullYear() == yyyy ) && ( xdata.getMonth () == mm - 1 ) && ( xdata.getDate() == dd ) )
  13. check = true;
  14. else
  15. check = false;
  16. } else
  17. check = false;
  18. return this.optional(element) || check;
  19. },
  20. "Please enter a correct date"
  21. );

Report this snippet  

You need to login to post a comment.