Created
August 16, 2013 04:28
-
-
Save zxmarcos/6247332 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function inserir(t, index, str) { | |
| return t.substring(0, index) + str + t.substring(index, index + t.length); | |
| } | |
| function trocar(t, index, str) { | |
| return t.substr(0, index) + str + t.substr(index+str.length); | |
| } | |
| function validarHora(evt, controle) { | |
| var evento = evt || window.event; | |
| var tecla = evento.keyCode || evento.which; | |
| var input = document.getElementById(controle); | |
| tecla = String.fromCharCode(tecla); | |
| /* Expressões regulares para formar um padrão de hora */ | |
| var regex = new Array( | |
| /^[0-2]$/, | |
| /^(([0-1][0-9])|(2[0-3]))$/, | |
| /^(([0-1][0-9])|(2[0-3])):$/, | |
| /^(([0-1][0-9])|(2[0-3])):([0-5])$/, | |
| /^(([0-1][0-9])|(2[0-3])):([0-5][0-9])$/, | |
| /^(([0-1][0-9])|(2[0-3])):([0-5][0-9]):$/, | |
| /^(([0-1][0-9])|(2[0-3])):([0-5][0-9]):([0-5])$/, | |
| /^(([0-1][0-9])|(2[0-3])):([0-5][0-9]):([0-5][0-9])$/ | |
| ); | |
| var texto = document.getElementById(controle).value; | |
| var pos = input.selectionStart; | |
| texto = inserir(texto, pos, tecla); | |
| document.getElementById("testador").innerHTML = texto; | |
| for (var i = 0; i < regex.length; i++) { | |
| if (regex[i].test(texto)) { | |
| document.getElementById("label").innerHTML = "Aceito" + pos; | |
| return true; | |
| } | |
| } | |
| document.getElementById("label").innerHTML = "Rejeitado" + pos; | |
| if (evento.preventDefault) | |
| evento.preventDefault(); | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment