数值数据的文本框验证 [英] TextBox Validation for Numeric Data

查看:71
本文介绍了数值数据的文本框验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
谁能告诉我如何使用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.

推荐答案

您可以使用 Jquery插件验证/ [ ^ ]轻松实现您想要的功能.
You can use Jquery Plugin Validation/[^] to easily achieve what you want.


JQuery是一个JavaScript框架.

如果您想使用纯js,请在文本框onkeypress事件上使用此功能:
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>


这篇关于数值数据的文本框验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆