如何使用jquery验证仅应使用整数填充的字段? [英] How can i use jquery to validate a field that should be filled with integers only?
本文介绍了如何使用jquery验证仅应使用整数填充的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的整个项目提交都仅由于这一问题而未决.我已使用jquery形式进行了所有验证,以便我可以快速,良好地使用它,但我陷入了困境.请您帮我解决这个问题问题.
My entire project submission is pending only because of this one issue.I have used all validation in jquery form so that i could be fast and good for the use but i am stuck in this.could you please help me out in this issue.
推荐答案
我以两种方式处理了此问题.
I handled this issue in 2 ways.
1)用户也可以输入字符,但是在提交时,用户将收到类似值应为数字"的警报
1) User can enter characters also but on submission time user will get alert like 'Value should be a numeric'
2)不允许用户在文本字段中输入字符
2) Not allow user to enter character in text field
示例为 http://jsfiddle.net/2dJAN/25/
<input type="text" id ="fax_field" name="fax_field"/>
$("#fax_field").keyup(function(event) {
var limitField = $(this).val().trim().length;
this.value = this.value.replace(/[^0-9_\-\.]/g, '');
});
这篇关于如何使用jquery验证仅应使用整数填充的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文