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
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);
}