Skip to content

Instantly share code, notes, and snippets.

@Vampre
Created October 18, 2012 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Vampre/3913238 to your computer and use it in GitHub Desktop.
Save Vampre/3913238 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