Digital Regular Filter
| The code is as follows |
Copy Code |
|
if (Preg_match ("/^\d*$/", $yebihai))
Echo (' is a number ');
Else
Echo (' not number ');
or use a function
if (Is_numeric ($yebihai))
Echo (' is a number ');
Else
Echo (' not number '); |
The difference between the two methods is that the Is_numeric decimal is also considered a number, and the decimal point is preceded by a character.
Regular expressions are the following numbers and letters:
| The code is as follows |
Copy Code |
|
$password = ' ABC12 ';
if (!preg_match (/^) ([a-z]+[0-9]+) | ( [0-9]+[a-z]+)] [a-z0-9]*$/i, $password)) {
Echo ' Password must be a combination of numbers and letters ';
} |
If you want to limit the length of 6-15-bit English characters and numbers
As long as you add a strlen to judge the following $plen<6| | $plen >15
| The code is as follows |
Copy Code |
|
$password = ' abc123 ';
$plen =strlen ($password);
if (!preg_match (/^) ([a-z]+[0-9]+) | ( [0-9]+[a-z]+)] [a-z0-9]*$/i, $password) | | $plen <6| | $plen >15) {
Echo ' Password must be a combination of 6-15 digits and letters ';
} |
In fact, we can also use regular to limit the length
We can refer to the rules for length.
Verify the N-bit number: ^\d{n}$
Verify at least n digits: ^\d{n,}$
Verify the number of m-n bits: ^\d{m,n}$
The above is a number, we can combine the verification of just add a {} on it.
| The code is as follows |
Copy Code |
|
$password = ' abc123 ';
$plen =strlen ($password);
if (!preg_match (/^) ([a-z]+[0-9]+) | ( [0-9]+[a-z]+)] [a-z0-9]*{8,}$/i, $password) | | $plen <6| | $plen >15) {
Echo ' Password must be a combination of 8 digits and letters ';
} |
The length is 8 or more in fact, just add a {8 after the regular,} on it,