Created
July 3, 2013 14:10
-
-
Save kikobr/5918184 to your computer and use it in GitHub Desktop.
Input Text
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
//<input type="text" onkeydown="return digita_numero(this, event);" /> | |
function digita_numero(input, e){ | |
var elementos = input.form.elements; | |
var maxlength = input.getAttribute('maxlength'); | |
//Se o evento for número ou teclas especiais, passa. | |
if(e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode== 8 || e.keyCode== 9 || e.keyCode== 13 || e.keyCode== 27 || e.keyCode== 32 || e.keyCode>= 37 && e.keyCode <= 40 ){ | |
} | |
else if(e.which >= 96 && e.which <= 105 || e.which >= 48 && e.which <= 57 || e.keyCode== 8 || e.keyCode== 9 || e.keyCode== 13 || e.keyCode== 27 || e.keyCode== 32 || e.keyCode>= 37 && e.keyCode <= 40 ){ | |
} | |
//Caso contrário, cancela o input (IMPORTANTE -> ONKEYDOWN pra dar o timing.) | |
else{ | |
return false; | |
} | |
// Chegou ao limite de dígitos, pula pro próximo elemento | |
//IMPORTANTE -> Funciona melhor com onkeyup! | |
if(input.value.length == maxlength){ | |
for(var i=0; i < elementos.length; i++){ | |
//Input que disparou a função | |
if(input == elementos[i]){ | |
//Pula para próximo input do tipo texto | |
for(var x=i+1; x < elementos.length; x++){ | |
if(elementos[x].type == "text"){ | |
elementos[x].focus(); | |
break; //Encerra este loop. | |
} | |
} | |
break; | |
} | |
} | |
} | |
} |
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
//<input type="text" onblur="return simple_check_email(this);" /> | |
//IMPORTANTE -> Validação super simples e usar o ONBLUR. | |
function simple_check_email(input){ | |
var regExp = /\S+@\S+\.\S+/; | |
//Se o e-mail informado não estiver no formato correto | |
if(regExp.test(input.value) == false){ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment