Reputation: 313
How to check the textbox value is string or integer in jquery
if ($('#TournamentFee').is(NaN)) {
alert("String");
} else {
alert("Int");
}
Upvotes: 2
Views: 103
Reputation: 28837
You could use:
$.isNumeric($('#TournamentFee').val())
Using jQuery's .isNumeric()
Upvotes: 2
Reputation: 35973
try this:
function isNumber(n) {
n = n.replace(',','.');
return !isNaN(parseFloat(n)) && isFinite(n);
}
var str = $('#TournamentFee').val();
if (!isNumber(str) {
alert("String");
} else {
alert("Int");
}
Upvotes: 1