简体   繁体   中英

How i can valid number only without character by php regular expression

如何通过php正则表达式只有没有字符的有效数字

if( filter_var("32", FILTER_VALIDATE_FLOAT) !== false) {
    echo "Valid number";
}

if( filter_var("ab", FILTER_VALIDATE_FLOAT) === false) {
    echo "Invalid Number";
}

http://php.net/manual/en/book.filter.php

http://www.php.net/manual/en/filter.filters.validate.php

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM