Input Field accepting only numbers using javascript

<input name=”demo” type=”text” id=”demo” onkeypress=”var unicode=event.keyCode? event.keyCode : event.charCode;if ((unicode < 32 || unicode > 33)&&(unicode < 45 || unicode > 57))  return false; return true;”>

This code compatible to all browsers !


me : yeay its me arun

4 comments on “Input Field accepting only numbers using javascript
  1. Kushal says:

    But this code is not working in FF

  2. Kushal says:

    Sorry!!! its working now
    the problem was in my side
    Sorry Once again

  3. Kushal says:

    Hi Arun,
    In your code doesnot allows the back space key.So i rewrite the code as follows
    function IsNumeric(event)
    var unicode=event.keyCode? event.keyCode: event.charCode;
    if ((unicode 33)&&(unicode 57) )
    return true;
    return false;
    return true;


  4. R Arun Raj says:

    Thanks Kushal ..

    Good job ..


Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.