Home >Backend Development >PHP Tutorial >PHP gets the regular number of numbers in a string_PHP tutorial
filter_sanitize_number_int filter removes all illegal characters in numbers.
This filter allows all numbers as well as +-.
*/
$number="5-2+3pp";
var_dump(filter_var($number, filter_sanitize_number_int));
/*
Verification number: ^[0-9]*$
Verify n-digit number: ^d{n}$
Verify at least n digits: ^d{n,}$
Verify m-n digit number: ^d{m,n}$
Verify numbers starting with zero and non-zero: ^(0|[1-9][0-9]*)$
Verify a positive real number with two decimal places: ^[0-9]+(.[0-9]{2})?$
Verify positive real numbers with 1-3 decimal places: ^[0-9]+(.[0-9]{1,3})?$
Verify non-zero positive integers: ^+?[1-9][0-9]*$
Verify non-zero negative integers: ^-[1-9][0-9]*$
Verify non-negative integer (positive integer + 0) ^d+$
Verify non-positive integers (negative integers + 0) ^((-d+)|(0+))$
Validate characters of length 3: ^.{3}$
For more details, please check: http://www.bkjia.com/phper/php-function/35065.htm
*/