如何使用jquery进行数据类型检查验证? [英] how can i do data type check validation using jquery ?
本文介绍了如何使用jquery进行数据类型检查验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hii,
我想进行数据类型检查..在文本框中输入的值必须是双格式。我可以使用它比较验证器。但是我想用jquery来做。
解决方案
为此你可以使用 jQuery Validation Plugin
文档: http://jqueryvalidation.org/documentation [ ^ ]
数字方法
http://jqueryvalidation.org/number-method [ ^ ]
样品
< !doctype html >
< html >
< head >
< meta charset = utf-8 >
< title > 只需要字段和十进制数字。< / title >
< link rel = stylesheet href = http://jquery.bassistance.de/validate/demo/site-demos.css >
< / head >
< body >
< 表格 id = myform >
< label = 外商投资企业ld > 必填,十进制数:< / label >
< input class = left id = field name = field >
< br / >
< 输入 type = 提交 值 = 验证! >
< / form >
< script src = http://code.jquery.com/jquery-1.9.1.min.js > < / script >
< script 跨度> src = http://jquery.bassistance.de/validate/jquery.validate.js > < / script >
< script src = http://jquery.bassistance.de/validate/additional-methods.js > < / script >
< script >
//仅用于演示,避免表单提交
jQuery.validator.setDefaults({
debug:true,
success:valid
});
(#myform) .validate({
规则:{
字段:{
required:true,
number:true
}
}
});
< / script >
< / body >
< / html >
我希望这会对你有所帮助。
您可以使用Javascript的parsefloat()函数来验证文本框。
http://www.w3schools.com/jsref/jsref_parseFloat.asp [ ^ ]
你可以试试这样的东西.. 。
请不要复制粘贴,我给你提示......
Hii,
I want to do data type check .. value entered in text box must be in double format. I can use it compare validator for that . but i want to do it using jquery .解决方案For that you can use jQuery Validation Plugin
Documentation :http://jqueryvalidation.org/documentation[^]
number method
http://jqueryvalidation.org/number-method[^]
Sample
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Makes "field" required and a decimal number only.</title> <link rel="stylesheet" href="http://jquery.bassistance.de/validate/demo/site-demos.css"> </head> <body> <form id="myform"> <label for="field">Required, decimal number: </label> <input class="left" id="field" name="field"> <br/> <input type="submit" value="Validate!"> </form> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script> <script src="http://jquery.bassistance.de/validate/additional-methods.js"></script> <script> // just for the demos, avoids form submit jQuery.validator.setDefaults({ debug: true, success: "valid" });
( "#myform" ).validate({ rules: { field: { required: true, number: true } } }); </script> </body> </html>
I hope this will help to you.
Hi,
You can use Javascript's parsefloat() function to validate the textbox.
http://www.w3schools.com/jsref/jsref_parseFloat.asp[^]
You can try something like this...
Please don't copy and paste, I'm giving you the hint...
这篇关于如何使用jquery进行数据类型检查验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文