Click here to Skip to main content
15,914,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
{
       var AsciiValue=event.keyCode||event.charcode;
           if((AsciiValue>=48 && AsciiValue<=57) || (AsciiValue==8 || AsciiValue==127))
               event.returnValue=true;
           else
               event.returnValue=false;
       }




i have used this code..It works at all browers.
but it doesn't work at FireFox.
Posted

1 solution

Try this....:)

JavaScript
<script language="javascript">
         function blockChar() {
             var str = document.getElementById('txt').value;
             str = str.replace(/[^\d]*/g, '');
             document.getElementById('txt').value = str;
         }
    </script>


C#
<body onload="javascript:document.getElementById('txt').focus();">
    <input type="text" id='txt' onkeyup="blockChar();" />
</body>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900