Home > Backend Development > PHP Tutorial > PHP regular expression to verify numbers_PHP tutorial

PHP regular expression to verify numbers_PHP tutorial

WBOY
Release: 2016-07-20 11:01:48
Original
1147 people have browsed it

php tutorial regular expression verification number

Non-negative floating point number (positive floating point number + 0): ^d+(.d+)?$
Positive floating point number ^(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]* .[0-9]+)|([0-9]*[1-9][0-9]*))$
Non-positive floating point number (negative floating point number + 0) ^((-d+(.d+)?)|(0+(.0+)?))$
Negative floating point number ^(-(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9 ]*.[0-9]+)|([0-9]*[1-9][0-9]*)))$
Floating point number ^(-?d+)(.d+)?


^[1-9]d*$  ​​

//Match positive integers

^-[1-9]d*$  

//Match negative integers

^-?[1-9]d*$

//Match integers

^[1-9]d*|0$ 

//Match non-negative integers (positive integers + 0)

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

//Match non-positive integers (negative integers + 0)

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

//Match positive floating point numbers

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

//Match negative floating point numbers

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

//Match floating point numbers

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

// Match non-negative floating point numbers (positive floating point numbers + 0)

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

// Match non-positive floating point numbers (negative floating point numbers + 0)


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}$

?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445417.htmlTechArticlephp tutorial regular expression verification of digital non-negative floating point number (positive floating point number + 0): ^d+(.d+ )?$ Positive floating point number^(([0-9]+.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0- 9]*.[0-9]+)|([0-9]*[1-9][0-9]*))$ Not...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template