Home  >  Article  >  php教程  >  php获取字符串中数字正则

php获取字符串中数字正则

WBOY
WBOYOriginal
2016-06-13 11:18:42855browse

 

filter_sanitize_number_int 过滤器删除数字中所有非法的字符。

该过滤器允许所有数字以及 +-。
*/

$number="5-2+3pp";

var_dump(filter_var($number, filter_sanitize_number_int));

/*
验证数字:^[0-9]*$
验证n位的数字:^d{n}$
验证至少n位数字:^d{n,}$
验证m-n位的数字:^d{m,n}$
验证零和非零开头的数字:^(0|[1-9][0-9]*)$
验证有两位小数的正实数:^[0-9]+(.[0-9]{2})?$
验证有1-3位小数的正实数:^[0-9]+(.[0-9]{1,3})?$
验证非零的正整数:^+?[1-9][0-9]*$
验证非零的负整数:^-[1-9][0-9]*$
验证非负整数(正整数 + 0)  ^d+$
验证非正整数(负整数 + 0)  ^((-d+)|(0+))$
验证长度为3的字符:^.{3}$

更多详细内容请查看:http://www.bkjia.com/phper/php-function/35065.htm
*/


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn