Javascript function that is equivalent for PHP function
This question already has an answer here:
Use regular expressions.
if (/-?d+(?:.d*)?(?:[eE][+-]?d+)?/.test(yourInput)) {
// Do something
}
Of course, this will only work on strings. For a different method, see a duplicate question:
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
To only check if the input contains a number (0-9) at all, regex works again:
if (/[0-9]+/.test(yourInput)) {
// Do something
}
如果所讨论的变量是$first_name
if( $first_name && !isNaN($first_name[0])) {
// do something
}
在js中检查数字变量是否是一个数字:
isFinite(number) && !isNaN(parseFloat(number))
链接地址: http://www.djcxy.com/p/26408.html
上一篇: 搜索json号码
下一篇: Javascript功能相当于PHP功能