Skip to content

Instantly share code, notes, and snippets.

@renoirtech
Created November 4, 2015 17:22
Show Gist options
  • Save renoirtech/dc6e2bf94e23f6bf9ef2 to your computer and use it in GitHub Desktop.
Save renoirtech/dc6e2bf94e23f6bf9ef2 to your computer and use it in GitHub Desktop.
Função para verificar se um campo possui apenas números.
function teclaPermitida(event) {
if ((event.keyCode == 8) || (event.keyCode == 46) || (event.keyCode == 9) || (event.keyCode == 37) || (event.keyCode == 39) || (event.keyCode == 116) || (event.keyCode == 16) || (event.keyCode == 36)) {
return true;
} else {
return false;
}
}
function sonum(event) {
if (window.event) var event = window.event;
//alert(event.keyCode);
var tecla = event.keyCode;
//remapeia o codigo das teclas do teclado numerico
if ((tecla >= 96) && (tecla <= 105)) {
var tecla = tecla - 48;
}
if (teclaPermitida(event)) return true;
if ((tecla < 48) || (tecla > 57) && (tecla != "0") && (tecla != 8)) {
//event.keyCode = 0;
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment