[input] Type in numbers in the input box.

Object 
  • To Type in ONLY numbers in the input box.
  • To support cross-browsing.
Source
<html>
<body>
<script type="text/javascript">
function noNumbers(e)
{
var keynum;
var keychar;
var numcheck;

if(window.event) // IE
{
keynum = e.keyCode;
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}
keychar = String.fromCharCode(keynum);
numcheck = /\d/;
alert("aa" + keychar );
return !numcheck.test(keychar);
}
</script>

<form>
Type some text (numbers not allowed):
<input type="text" onkeypress="return noNumbers(event)" />
</form>

</body>
</html>


if you know how to use regExp in javascript, you could reduce the source.
It'll help someone who works with you reads codes easily.

댓글

가장 많이 본 글