时间:2021-07-01 10:21:17 帮助过:36人阅读
$str = '0510-12323475,,'; $pattern = '/,?\d{4}-\d+,?/'; var_dump(preg_match($pattern, $str));
------解决方案--------------------
$ar = array( '0510-12323475,0781-26354589,021-25698746', '0521-25698745,,', '0521-25698745,021-25698475', '0317-88641,ttttttt', ); $pattern = '/(?:\d{3,}-\d+,|,){3}/'; foreach($ar as $v) { $v = trim($v) . str_repeat(',', 3-substr_count($v, ','));//补齐逗号 echo $v . ' ' . preg_match($pattern, $v) , PHP_EOL; }
------解决方案--------------------