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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -