Created
July 2, 2012 13:30
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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