我想在使用之前使用正则表达式验证我的数字,但是它没有成功。
我希望第一个数字以0开头,接着是2或5,然后是4,其余的数字继续到10位数。
<?php $str = "0241310102"; $pattern = "([0]{1}[2,5]{1}[4]{1}[0-9]{7})"; if(preg_match($pattern, $str)){ echo "YES"; }else{ echo "NO"; } ?>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
^
,$
)。[0]
→0
0{1}
→0
[2,5]
将包括字符类中的逗号→[25]