Home > php教程 > php手册 > php 正则表达式验证数字

php 正则表达式验证数字

WBOY
Release: 2016-06-13 11:18:00
Original
1316 people have browsed it

 

php教程 正则表达式验证数字

非负浮点数(正浮点数 + 0):^d+(.d+)?$
正浮点数   ^(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*))$
非正浮点数(负浮点数 + 0) ^((-d+(.d+)?)|(0+(.0+)?))$
负浮点数  ^(-(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*.[0-9]+)|([0-9]*[1-9][0-9]*)))$
浮点数  ^(-?d+)(.d+)?


^[1-9]d*$    

 //匹配正整数 

^-[1-9]d*$   

 //匹配负整数 

^-?[1-9]d*$ 

 //匹配整数 

^[1-9]d*|0$   

//匹配非负整数(正整数 + 0) 

^-[1-9]d*|0$ 

 //匹配非正整数(负整数 + 0) 

^[1-9]d*.d*|0.d*[1-9]d*$  

  //匹配正浮点数 

^-([1-9]d*.d*|0.d*[1-9]d*)$  

 //匹配负浮点数 

^-?([1-9]d*.d*|0.d*[1-9]d*|0?.0+|0)$  

 //匹配浮点数 

^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$  

  //匹配非负浮点数(正浮点数 + 0) 

^(-([1-9]d*.d*|0.d*[1-9]d*))|0?.0+|0$  

 //匹配非正浮点数(负浮点数 + 0)


验证数字:^[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}$

?>


source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template