Sean's Personal Code Samples And References

Numbers Only

Javascript function to only allow numbers in a textbox.


Example Textbox

<input type="text" name="txtExample" id="txtExample" onkeydown="return NumbersOnly(event);" />
Javascript Code

<script type="text/javascript">
function NumbersOnly(evnt){

	var key = evnt.keyCode? evnt.keyCode : evnt.charCode
	//DELETE = 46
	//BACKSPACE = 8
	//ZERO = 48; 9 = 57 KEYBOARD KEYS
	//ZERO = 96; 9 = 105 NUMBER PAD KEYS
	if((key > 95 && key < 106) || (key > 47 && key < 58) || key == 8)
		return true;
    
	return false
}
</script>
Sean Marcellus
There are 10 kinds of people e in this world, those who understand binary and those who don’t.