Skip to content

Instantly share code, notes, and snippets.

@sendoa
Created July 2, 2012 13:30
Show Gist options
  • Save sendoa/3033254 to your computer and use it in GitHub Desktop.
Save sendoa/3033254 to your computer and use it in GitHub Desktop.
Método adicional para jQuery Validator de comprobación de hora (hh:mm)
// Hay que añadirlo a additional-methods.js
jQuery.validator.addMethod("horahhmm", function(value, element) {
var res = false;
// Formato hh:mm
res = this.optional(element) || /^\d{2}[:]\d{2}$/.test(value);
var hora = value.split(':');
var hh = parseInt(hora[0],10);
var mm = parseInt(hora[1],10);
if (hh < 0 || hh > 23) res = false;
if (mm < 0 || mm > 59) res = false;
return res;
}, "La hora indicada no es válida"
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment