If PHP matches the telephone expression correctly, write it by yourself. 1. If it is a phone number, there must be a horizontal bar between the area code and the phone number, and there must be area code 2. If it is a mobile phone number, mobile phones can be prefixed with "86", "86", "86-", and "86-" 3. The phone number can only match those in mainland China. There are three digits at the beginning of 02, and only 010 Beijing No. 4 at the beginning of 01 is supported.
If PHP matches the telephone expression correctly, write it by yourself. 1. If it is a phone number, there must be a horizontal bar between the area code and the phone number, and there must be area code 2. If it is a mobile phone number, mobile phones can be prefixed with "86", "86", "86-", and "86-" 3. The phone number can only match those in mainland China. There are three digits at the beginning of 02, and only 010 Beijing No. 4 at the beginning of 01 is supported.
PHP matches the phone format correctly.
1. If it is a phone number, there must be a horizontal bar between the area code and the phone number, and there must be a area code
2. If it is a mobile phone, You Can prefix it with "+ 86", "86", "86-", and "+ 86 -".
3. The phone number can only match those in mainland China. There are three places at the beginning of 02, and only the numbers of 010 Beijing are allowed at the beginning of 01
4. The extension number is 020-89571800-1,020-89571800-125.
5,400 hotline support
'/^ (\ +? 86 -?)? (18 | 15 | 13) [0-9] {9} $ /', 'tel '=>'/^ (010 | 02 \ d {1} | 0 [3-9] \ d {2 }) -\ d {7, 9} (-\ d + )? $/', '000000' =>'/^ 400 (-\ d {3, 4}) {2} $ /',); if ($ type & isset ($ regxArr [$ type]) {return preg_match ($ regxArr [$ type], $ tel )? True: false;} foreach ($ regxArr as $ regx) {if (preg_match ($ regx, $ tel) {return true ;}} return false ;} $ tm1 = microtime (true); $ arr = array ('000000', '+ 15910241024 000000', '000000',' + 86-15312001200 ', '000000 ', '20180101', '201-20180101', '20180101', '20180101', '20180101', '20180101', '20180101 ', '022-102410240 ', '2014-0222', '2014-020-9800 ', '2014-0588-010', '2014 -0211-0112 ',); foreach ($ arr as $ tel) {echo "\ n {$ tel }:\ t". (isTel ($ tel )? "Yes": "error");} echo sprintf ("\ n \ ntaken %. 6f s", microtime (true)-$ tm1 );
Test results:
X-Powered-By: PHP/5.2.0Content-type: text/html15910241024: Yes + 861591900 0000: Error 86159 1930: Error + 86-9100: Yes 15312001200: Yes 18655321002: error 020-89571800: Is 0755-102410240: Is 0553-10241024: Is 010-1204120140: Error 010-120412014: is 110-89571800: Error 022-102410240: Is 0222-102410241: error 400-020-9800: 400-0588-010: 400-0211-0112: taken 0.002274 s