I've learned the hard way that IE has some issues with with validating dates using the jQuery Validate Plugin (https://jqueryvalidation.org/).
My rule is simply starttime: {required: true, date: true}
but my format is DD-MMM-YYYY hh:mm a
, i.e. 31-Aug-2017 9:43 am.
This works in other browsers, but IE says it's an invalid date. Note, validation is working on other fields.
There are some great answers here: Custom date format with jQuery validation plugin but specifically, how can I validate my date format in IE?
My guess is that I need to add a custom method, but what should be in it? RegEx or a custom date, and how? I'm ok with RegEx validating the format of a date without validating the date itself (eg. 32/01/2017) because this page uses a datepicker and the user cannot enter data directly.
EDIT (to include actual code):
<script type="text/javascript" src="js/plugins/jquery-validate/jquery.validate.min.js"></script>
<script>
$(document).ready(function(){
if ($("#newinspectionform").length > 0) {
var validate = $("#newinspectionform").validate({
errorClass: "has-error",
validClass: "",
errorElement: "span",
ignore: [],
errorPlacement: function (error, element) {
$(element).after(error);
$(element).parents(".form-group").addClass("has-error");
},
highlight: function (element, errorClass) {
$(element).parents(".form-group").removeClass("has-success").addClass(errorClass);
},
unhighlight: function (element, errorClass, validClass) {
$(element).parents(".form-group").removeClass(errorClass).addClass(validClass);
},
rules: {
propertyid: {required: true},
type: {required: true},
starttime: {required: true, date: true},
endtime: {required: true, date: true}
}
});
}
... other stuff
</script>