admin 管理员组

文章数量: 887007

php座机正则,php电话正则

function isTel($tel,$type='')

{

$regxArr = array(

'sj' => '/^(\+?86-?)?(18|15|13)[0-9]{9}$/',

'tel' => '/^(010|02\d{1}|0[3-9]\d{2})-\d{7,9}(-\d+)?$/',

'400' => '/^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(

'15910241024',

'+861591900 0000',

'86159 1930 9100',

'+86-15312001200',

'18655321002',

'02089571800',

'020-89571800',

'0755-102410240',

'0553-10241024',

'010-1204120140',

'010-120412014',

'110-89571800',

'022-102410240',

'0222-102410241',

'400-020-9800',

'400-0588-010',

'400-0211-0112',

);

foreach ($arr as $tel)

{

echo "\n{$tel}:\t".(isTel($tel) ? "是":"错误");

}

echo sprintf("\n\ntaken %.6f s",microtime(true)-$tm1);

本文标签: php座机正则 php电话正则