Skip to content

Instantly share code, notes, and snippets.

@deivisonarthur
Forked from Vampre/apenasnum.js
Created October 18, 2012 17:09
Show Gist options
  • Save deivisonarthur/3913362 to your computer and use it in GitHub Desktop.
Save deivisonarthur/3913362 to your computer and use it in GitHub Desktop.
Função apenas números (limita a digitação somente de números em campos "text") colocar em <input type='text' onkeypress='return Apenas_Numeros(event);'>
function Apenas_Numeros(caracter)
{
var nTecla = 0;
if (document.all) {
nTecla = caracter.keyCode;
} else {
nTecla = caracter.which;
}
if ((nTecla> 47 && nTecla <58)
|| nTecla == 8 || nTecla == 127
|| nTecla == 0 || nTecla == 9 // 0 == Tab
|| nTecla == 13) { // 13 == Enter
return true;
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment