Click here to Skip to main content
15,921,577 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am developing an application where i want to validate the textbox which can accept only single dot(.), digits, and backspace and delete button. please help me to do this. i need this in hurry.
Posted

1 solution

Friend,

JavaScript
function onlyNumbers(evt)
{
    var e = event || evt; // for trans-browser compatibility
    var charCode = e.which || e.keyCode;
    if (charCode ==8 || charCode ==46 || charCode < 48 || charCode > 57 || charCode ==190)
    {
        return true;
    }
    else
    {
       return false;
    }
}


Reference
http://www.aspdotnetfaq.com/Faq/What-is-the-list-of-KeyCodes-for-JavaScript-KeyDown-KeyPress-and-KeyUp-events.aspx[^]

If useful accept and vote!!

Regards,
Karthik.J
 
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