Validate time with date.js

simple time validation with date js. credits to: http://stackoverflow.com/questions/4012702/parse-only-a-time-string-with-datejs

by Terrance Smith

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script>
<input id="time" type="text" value="2:00 pm" />
<button id='tester'>Test the time</button>

JavaScript

function validateTime(input) {
    return Date.parseExact(input, [
        "H:m",
        "h:mt",
        "h:m t",
        "ht", "h t"]) !== null || Date.parseExact(input, [
        "h:mtt",
        "h:m tt",
        "htt", "h tt"]) !== null;
}
$(document).ready(function () {
    $("#tester").click(function () {
        alert('Validating...');
        var result = validateTime($("#time").val());
        alert(result);
    });
});