你可以使用它,它会接受任何东西,但首字母和末字符将是字母数字。
if(preg_match('/^[A-Za-z0-9]{1}.*[A-Za-z0-9]{1}?$/i', $_GET['eq'])){
echo "<h1>true</h1>";
}else{
echo "<h1>false</h1>";
}
表达解释:
^ Beginning. Matches the beginning of the string, or the beginning of a line if the multiline flag (m) is enabled.
[ Character set. Match any character in the set.
A-Z Range. Matches a character in the range "A" to "Z" (char code 65 to 90).
a-z Range. Matches a character in the range "a" to "z" (char code 97 to 122).
0-9 Range. Matches a character in the range "0" to "9" (char code 48 to 57).
]
{1} Quantifier. Match 1 of the preceding token.
. Dot. Matches any character except line breaks.
* Star. Match 0 or more of the preceding token.
[ Character set. Match any character in the set.
A-Z Range. Matches a character in the range "A" to "Z" (char code 65 to 90).
a-z Range. Matches a character in the range "a" to "z" (char code 97 to 122).
0-9 Range. Matches a character in the range "0" to "9" (char code 48 to 57).
]
{1} Quantifier. Match 1 of the preceding token.
? Lazy. Makes the preceding quantifier lazy, causing it to match as few characters as possible.
$ End. Matches the end of the string, or the end of a line if the multiline flag (m) is enabled.