2

How to check the textbox value is string or integer in jquery

if ($('#TournamentFee').is(NaN)) {
  alert("String");
} else {
  alert("Int");
}
Dinesh Dinaz
  • 313
  • 1
  • 4
  • 13

2 Answers2

2

You could use:

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

Fiddle

Using jQuery's .isNumeric()

Sergio
  • 27,998
  • 10
  • 81
  • 130
1

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");
}
Alessandro Minoccheri
  • 34,369
  • 22
  • 118
  • 164