admin管理员组文章数量:1425753
I have a text box in the form which should allow only numeric values that is less than the boundary value 2147483647 (max value of Int32)? Can anybody help me in doing this with JQuery? I have tried using by adding a validate plugin in eclipse but it is not working. Thanks in advance.
I have a text box in the form which should allow only numeric values that is less than the boundary value 2147483647 (max value of Int32)? Can anybody help me in doing this with JQuery? I have tried using by adding a validate plugin in eclipse but it is not working. Thanks in advance.
Share Improve this question edited May 16, 2013 at 4:00 Sparky 98.8k26 gold badges202 silver badges290 bronze badges asked May 15, 2013 at 21:45 atlpeteratlpeter 191 silver badge3 bronze badges 4- 4 can you show us code? something you tried? We can help you, don't solve the problem for you. – steo Commented May 15, 2013 at 21:47
- 2 You should read this answer posted on another question. – Patartics Milán Commented May 15, 2013 at 21:50
- Do you want only positive integers less than 2147483647? – kennebec Commented May 15, 2013 at 21:59
- did any answer helped you?! – Muhammad Bekette Commented May 19, 2013 at 18:45
3 Answers
Reset to default 2here sample code:
$('#textboxID').on('change',function(){
if($(this).val()>=2147483647){
//put error span with nice css
}
});
HTML:
<input type="text" id="numberField" />
<input id="submit" type="submit" value="Submit" />
JQuery:
$('#submit').click(function(){
var numberField = $('#numberField');
var number = parseInt(numberField.val(), 10);
if(isNaN(number) || number > 2147483647){
numberField.val('');
alert('Not a number');
}
else
alert('Number is: '+ number);
});
jsFiddle http://jsfiddle/R3Rx2/1/
You could do something like this:
DEMO: http://jsfiddle/mSSYT/1/
$('#test').on('keyup', function (e) {
var $self = $(this),
v = $self.val(),
max = 2147483647;
//blank any input that isint a number
if (!/^\d*$/.test(v)) {
$self.val('');
return;
}
//trim the value until it meets the condition
if (v >= max) {
while (v >= max) {
v = v.substring(0, v.length - 1);
}
$self.val(v);
}
});
本文标签: jquerySet a max value to a text box in javascriptStack Overflow
版权声明:本文标题:jquery - Set a max value to a text box in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745449685a2658826.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论