JQuery Validation Engine : Change Date Format
My Datepicker code $(function(){ $( '#task_start_date').datepicker({ dateFormat: 'dd-M-yy', showOn: 'button', buttonImage :image_us,
Solution 1:
^(0?[1-9]|[12][0-9]|3[01])[-][A-Z]{3}[-]\d{2}$
This should do the trick. The regex you tried was for the format of dd/mm/yyyy or dd-mm-yyyy.
Solution 2:
Try this (not tested):
(?:0[1-9]|1[0-9]|2[0-9]|3[01])-(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)-\d{2}
(?:0[1-9]|1[0-9]|2[0-9]|3[01])
: match 01 to 09, 10 to 19, 20 to 29, 30 to 31. But Feb doesnt have anything over 29 so how you deal with that we not be regex based-
: match hypen(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)
: matches month-
: match hypen-\d{2}
: match any two digits in any order
You can shrink the regex but I dont have time right now.
Solution 3:
Use this one
"date": {
// Check if date is valid by leap year
"func": function (field) {
var pattern = new RegExp(/^(0?[1-9]|[12][0-9]|3[01])[\/\-\.](0?[1-9]|1[012])[\/\-\.](\d{4})$/);
var match = pattern.exec(field.val());
if (match == null)
return false;
var year = match[3];
var month = match[2]*1;
var day = match[1]*1;
var date = new Date(year, month - 1, day); // because months starts from 0.
return (date.getFullYear() == year && date.getMonth() == (month - 1) && date.getDate() == day);
},
"alertText": "* Invalid date, must be in dd-mm-yyyy format"
},
Post a Comment for "JQuery Validation Engine : Change Date Format"