JS script for validating date format:
"date": {
// Check if date is valid by leap year
"func": function (field) {
//var pattern = new RegExp(/^(\d{4})[\/\-\.](0?[1-9]|1[012])[\/\-\.](0?[1-9]|[12][0-9]|3[01])$/);
var pattern = new RegExp(/([12]\d|0[1-9]|3[0-1])-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\d{4}/);
var match = pattern.exec(field.val());
if (match == null)
return false;
/*var year = match[1];
var month = match[2]*1;
var day = match[3]*1;*/
var year = match;
var month = match[2];
var day = match[3];
var date = new Date(day, month - 1, year); // 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"
},
Here, the regex has been changed to work with the format dd-M-yy
. The regex is valid but it still shows the validation error when datepicker input is true.
How can I make the date format as dd-M-yy
i.e 26-Nov-2014
and it gives no validations if the format is correct ?
Thanks.