本文介绍了数值数据的文本框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
谁能告诉我如何使用JavaScript验证数字数据的文本框.该文本框应仅允许数字和十进制值(例如23或23.5).
在此先感谢.
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.
推荐答案
<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>
这篇关于数值数据的文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!