This article introduces an example of a regular expression for phone number matching in PHP. Friends in need can refer to it.
Regular expression example for phone number allocation: <?php /** * 匹配电话号码的正则实例 * edit bbs.it-home.org */ $preg = '/(^0?1[2,3,5,6,8,9]\d{9}$)|(^(\d{3,4})-(\d{7,8})$)|(^(\d{7,8})$)|(^(\d{3,4})-(\d{7,8})-(\d{1,4})$)|(^(\d{7,8})-(\d{1,4})$)/'; $b = '13345678901'; $b = '013215245245'; $b = '1234-12345678-1234'; if(preg_match($preg, $b)){ echo "匹配到了"; }else{ echo "没有匹配到"; } ?> Copy after login [2,3,5,6,8,9] Only these types of mobile phone numbers are provided: 12...,13...,15...,16...,18...,19.... Just add what's not enough and delete what's redundant. Perfectly supports various mobile phone numbers (supports mobile phone numbers containing 0 such as: 013545454875) and landline numbers. |