Skip to content

Instantly share code, notes, and snippets.

@sgsheg
Last active August 29, 2015 14:03
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 sgsheg/218fa339c0ea53a56e24 to your computer and use it in GitHub Desktop.
Save sgsheg/218fa339c0ea53a56e24 to your computer and use it in GitHub Desktop.
input only numberic
function validate(evt) {
	var theEvent = evt || window.event;
	var key = theEvent.keyCode || theEvent.which;
	key = String.fromCharCode( key );
	var regex = /[0-9]|\./;
	if( !regex.test(key) ) {
		// alert('hello')
	theEvent.returnValue = false;
	if(theEvent.preventDefault) theEvent.preventDefault();
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment