$(document).ready(function() {
$("#txtboxToFilter").keydown(function(event) {
// Allow: backspace, delete, tab and escape
if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 ||
// Allow: Ctrl+A
(event.keyCode == 65 && event.ctrlKey === true) ||
// Allow: home, end, left, right
(event.keyCode >= 35 && event.keyCode <= 39)) {
// let it happen, don't do anything
return;
}
else {
// Ensure that it is a number and stop the keypress
if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
event.preventDefault();
}
}
});
});
OR you can use
if($('#Field').val()!=""){ var value = $('#Field').val().replace(/^\s\s*/,'').replace(/\s\s*$/,''); var intRegex =/^\d+$/; if(!intRegex.test(value)){ errors +="Field must be numeric.<br/>"; success =false; } }else{ errors +="Field is blank.</br />"; success =false; }
If you like this post please mark as an answer so it will help others.
DivakarGanta
Member
39 Points
140 Posts
button onclick to textbox numeric value validation in Jquery
Apr 28, 2012 11:37 AM|LINK
Hi,
I have requirement for button click to popup alert if textbox is not a numeric value.
Thanks,
Ashley.Jones
Member
210 Points
51 Posts
Re: button onclick to textbox numeric value validation in Jquery
Apr 28, 2012 11:45 AM|LINK
Hello,
Please check the thread below.It will help you.
http://stackoverflow.com/questions/793445/getting-a-integer-value-from-a-textbox-how-to-check-if-its-nan-or-null-etc
Pritesh Meht...
Member
246 Points
151 Posts
Re: button onclick to textbox numeric value validation in Jquery
Apr 29, 2012 03:33 AM|LINK
Use following :
asteranup
All-Star
30184 Points
4906 Posts
Re: button onclick to textbox numeric value validation in Jquery
Apr 30, 2012 06:26 AM|LINK
Hi,
You can use this logic-
http://forums.asp.net/p/1650178/4289869.aspx#4289869
http://delicious.com/anupdg/numberonly
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: button onclick to textbox numeric value validation in Jquery
Apr 30, 2012 06:35 AM|LINK
Refer
http://www.aspforums.net/Threads/183574/How-To-Validate-the-Textbox-For-Inserting-Only-Numeric-Values/Answered
Contact me