numbers - Js isDigit - 在JavaScript中验证十进制数-IsNumeric()

JS check if Number / javascript / validation

在JavaScript中验证十进制数的最简洁、最有效的方法是什么?

测试案例。

01. IsNumeric('-1')      => true
02. IsNumeric('-1.5')    => true
03. IsNumeric('0')       => true
04. IsNumeric('0.42')    => true
05. IsNumeric('.42')     => true
06. IsNumeric('99,999')  => false
07. IsNumeric('0x89f')   => false
08. IsNumeric('#abcdef') => false
09. IsNumeric('1.2.3')   => false
10. IsNumeric('')        => false
11. IsNumeric('blah')    => false

12 revs, 9 users 30%



Answer #1
return (input - 0) == input && input.length > 0;
var temp = '' + input;
return (input - 0) == input && temp.length > 0;