jQuery Date Validation (YYYY-MM-DD) -
i need validate date using this script in format of yyyy-mm-dd, can't seem working perfectly. regular expression i'm using, allows users enter 10 numbers without dashes, instead of 8 dashes in correct places. there way modify script fix this?
jquery.validator.addmethod("date", function(date, element) { return this.optional(element) || date.match(/^[-0-9]{10}$/); }, "please specify valid date");
you have wrong regex.
you can use 1 instead :
^\d{4}-((0\d)|(1[012]))-(([012]\d)|3[01])$
so :
return this.optional(element) || date.match(/^\d{4}-((0\d)|(1[012]))-(([012]\d)|3[01])$/);
Comments
Post a Comment