Skip to content

Instantly share code, notes, and snippets.

@sipple
Created October 23, 2012 16:35
Show Gist options
  • Save sipple/3939944 to your computer and use it in GitHub Desktop.
Save sipple/3939944 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-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$/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