Skip to content

Instantly share code, notes, and snippets.

@allusis
Last active December 17, 2015 06:08
Show Gist options
  • Save allusis/1423a044e311da5a0ef1 to your computer and use it in GitHub Desktop.
Save allusis/1423a044e311da5a0ef1 to your computer and use it in GitHub Desktop.
Apex - input number only
<script>
function isNumberOnly(evt) {
var charCode = (evt.which) ? evt.which : evt.keyCode;
//console.log(charCode);
if(charCode == 110 || charCode == 190) {
return true;
}
if (charCode != 46 && charCode > 31
&& (charCode < 48 || charCode > 57 && charCode < 96 || charCode > 105)) {
evt.preventDefault();
return false;
}
return true;
}
</script>
<apex:inputText onKeyDown="isNumberOnly(event);" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment