如何通过php正则表达式只有没有字符的有效数字
if( filter_var("32", FILTER_VALIDATE_FLOAT) !== false) {
echo "Valid number";
}
if( filter_var("ab", FILTER_VALIDATE_FLOAT) === false) {
echo "Invalid Number";
}
if (!preg_match("/^([0-9]{1,6})$/", $variable) ¦¦ (is_numeric($variable) != 1))
{
echo ("This is not a valid entry");
}
如果你只想允许零或正整数(没有符号),你可以使用ctype_digit( )
Why regex? Use is_numeric() function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.