选择语言 :

 Core_Valid::numeric

Checks whether a string is a valid number (negative and decimal numbers allowed).

Uses {@link http://www.php.net/manual/en/function.localeconv.php locale conversion} to allow decimal point to be locale specific.

boolean Core_Valid::numeric( string $str )

参数列表

参数 类型 描述 默认值
$str string Input string
返回值
  • boolean
File: ./core/classes/valid.class.php
public static function numeric($str)
{
    // Get the decimal point for the current locale
    list ($decimal) = array_values(localeconv());

    // A lookahead is used to make sure the string contains at least one digit (before or after the decimal point)
    return (bool)preg_match('/^-?+(?=.*[0-9])[0-9]*+' . preg_quote($decimal) . '?+[0-9]*+$/D', (string)$str);
}