Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
How to validate integer for a textbox via javascript in asp.net
Posted

function isNumberKey(textboxvalue)
{
evt=textboxvalue.text;
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
textboxvalue.text="Enter in Integer Only";
return false;

return true;
}
 
Share this answer
 
Hello,

C#
var intRegex = /^\d+$/;
if(intRegex.test(someNumber)) {
   alert('I am an int');
   ...
}


Cya
 
Share this answer
 
Try this. Please note that the "===" is placed there on purpose.

JavaScript
function isInteger(value) {
    if ($.trim(value) === "") { return true; }
    if ((parseFloat(value) == parseInt(value)) && !isNaN(value) && parseInt(value) > 0) {
        return true;
    } else {
        return false;
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900