Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
Can any one please tell me how to validate a textbox using javascript for numeric data. The textbox should allow only numbers and decimal values(for e.g., 23 or 23.5).

Thanks in Advance.
Posted

You can use Jquery Plugin Validation/[^] to easily achieve what you want.
 
Share this answer
 
Comments
bedathur_ganesh 13-Jul-10 6:55am    
Thanks for the reply.. but, I want it to be implemented using javascript.. Can you please tell me how I can do it?
JQuery is a javascript framework.

If you want pure js use this function on textbox onkeypress event:
<code>function CheckNumeric (e)
{
var key;
key = e.which ? e.which : e.keyCode;
if((key>=48 && key<=57)) {
e.returnValue= true;
}
else
{
alert("please enter Numeric only");
e.returnValue = false;
}
}</code>
 
Share this answer
 
v2

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