我想知道如何检查正则表达式或其他什么,如果一个数字从0或00开始我这样做但新手到正则表达式
preg_match("/^[0][0-9]+$/", $number)
Run Code Online (Sandbox Code Playgroud)
您可以尝试以下代码
if (preg_match("~^0\d+$~", $number)) {
// Yes
}
else {
// no
}
Run Code Online (Sandbox Code Playgroud)
说明:
^ the beginning of the string
0 '0'
\d+ digits (0-9) (1 or more times)
$ before an optional \n, and the end of the
string
Run Code Online (Sandbox Code Playgroud)