I am looking for a way to validate user-entered time fields by comparing the closing time to opening time. The opening time CANNOT be greater than the closing time.
I am able to get an entry level validation, but would like to include military time and/or AM/PM validation to this.
Below is a screenshot of my form:
Below is the code I'm using:
//Start time validation $('.masterClose').on('blur','input', function() { var startTime = $('.masterOpen input').val(); var endTime = $('.masterClose input').val(); var msgText = ("Closing time must be after " + startTime + ". Please update time(s)"); if (startTime > endTime) { alert(msgText); } }); //End time validation
This code is working for time less than the entered value. This code does NOT take into account AM/PM
Example seen above (03:00 pm and 02:59 pm) throws the correct alert. However, if I enter 03:00pm and 10:00am, the alert message does not appear.
Can anyone provide some guidance on how to accommodate AM/PM in this validation?
Thanks,
Nate