In my last example, I had posted how to
validate date in Jquery, but if you are using datepicker then you
need not write a long script to validate date, instead you can easily
validate date by using your jquery.ui.datepicker.js library
itself.
function validateDate(ctrlClass, dateFormat) {
var isValid = true;
var date = $('.' +
ctrlClass).val();
var regexp = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
if (regexp.test(date)) {
try {
jQuery.datepicker.parseDate(dateFormat, date, null);
}
catch (error) {
isValid = false;
}
}
else {
isValid = false;
}
return isValid;
}
You just need to pass control class
name on which you want to perform validation with date format(i.e.
'mm/dd/yyyy' etc.)
Comments
Post a Comment