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
  • 28,539
  • 11
  • 85
  • 132
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
  • 35,521
  • 22
  • 122
  • 171