Dinesh Dinaz
Dinesh Dinaz

Reputation: 313

Jquery textbox value checking

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

Answers (2)

Sergio
Sergio

Reputation: 28837

You could use:

$.isNumeric($('#TournamentFee').val())

Fiddle

Using jQuery's .isNumeric()

Upvotes: 2

Alessandro Minoccheri
Alessandro Minoccheri

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

Related Questions