Skip to content

Instantly share code, notes, and snippets.

@ihsanberahim
Created November 29, 2014 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihsanberahim/aa4ee5604032bedee2b2 to your computer and use it in GitHub Desktop.
Save ihsanberahim/aa4ee5604032bedee2b2 to your computer and use it in GitHub Desktop.
Block input example
<html>
<body onload="onBodyLoad()">
<input name="intergerField"/>
</body>
</html>
window.integerOnly = function(elem) {
if (event.keyCode>=48 && event.keyCode<=57){
}else
{
return false;
}
return true;
};
function onBodyLoad()
{
document.querySelector('input[name="intergerField"]').setAttribute('onkeydown',"return integerOnly(this)");
}
/*
CREDIT
http://ihsanberahim.com
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment