Skip to content

Instantly share code, notes, and snippets.

@brennen
Forked from sipple/gist:3939944
Created October 23, 2012 16:47
Show Gist options
  • Save brennen/3940014 to your computer and use it in GitHub Desktop.
Save brennen/3940014 to your computer and use it in GitHub Desktop.
Time validation
<script type="text/javascript">
jQuery(document).ready(function($){
$('.datepicker').datepicker({ changeMonth: true, changeYear: true, minDate: '-1y', maxDate: '+3y'});
$.validator.addMethod("time", function(value, element) {
return this.optional(element) || /^(([0-1]?[0-2])|([2][0-3])):([0-5]?[0-9])(a|p)m?$/i.test(value);
}, "Please enter a valid time.");
$("#post").validate({
rules: {
time: "required time"
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment