gpt4 book ai didi

php - 检查数字是否以 0 或 00 开头

转载 作者:行者123 更新时间:2023-12-04 21:20:18 26 4
gpt4 key购买 nike

如果数字以 0 或 00 开头,我想知道如何使用正则表达式进行检查
我这样做了,但我是正则表达式的新手:

preg_match("/^[0][0-9]+$/", $number)

最佳答案

你可以试试下面的代码

if (preg_match("~^0\d+$~", $number)) {
// Yes
}
else {
// no
}

说明:
^                        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

DEMO

关于php - 检查数字是否以 0 或 00 开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26484914/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com