I am using jquery-1.3.2.js with the jquery.validate.js plugin and I am using the following code to try and validate an optional time field.
$.validator.addMethod('time', function(value) {
return /(^([0-9]|[0-1][0-9]|[2][0-3]):([0-5][0-9])(\s{0,1})(AM|PM|am|pm|aM|Am|pM|Pm{2,2})$)|(^([0-9]|[1][0-9]|[2][0-3])(\s{0,1})(AM|PM|am|pm|aM|Am|pM|Pm{2,2})$)/.test(value);
}, 'Please enter a valid time in the format of mm:hh am');
$.validator.addClassRules({
time: {
required: true,
time: true
},
timeOptional: {
required: false,
time: true
}
});
When I add a class to my textbox that is of "timeOptional", and I do not enter anything in the textbox, when the form is submitted I get the message of "Please enter a valid time in the format of mm:hh am."
How can I change this so that the form will allow a null value to be submitted in this textbox?