I would suggest using regexes:
var intRegex = /^d+$/;
var floatRegex = /^((d+(.d *)?)|((d*.)?d+))$/;
var str = $('#myTextBox').val();
if(intRegex.test(str) || floatRegex.test(str)) {
alert('I am a number');
...
}
Or with a single regex as per @Platinum Azure's suggestion:
var numberRegex = /^[+-]?d+(.d+)?([eE][+-]?d+)?$/;
var str = $('#myTextBox').val();
if(numberRegex.test(str)) {
alert('I am a number');
...
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…