Boo-urns Posted March 6, 2009 Share Posted March 6, 2009 I have a phone number setup like this (381) 323-4567 When I set it up to use on a page with a javascript function I need it setup like so 381 323 4567 I have no idea how to setup that regex. I've looked at some tutorials but still have had no luck. Thanks in advance for the help! Link to comment https://forums.phpfreaks.com/topic/148268-solved-phone-regex/ Share on other sites More sharing options...
Maq Posted March 6, 2009 Share Posted March 6, 2009 Here's some phone # regexes that may help you: http://regexlib.com/DisplayPatterns.aspx?categoryId=7&cattabindex=2 Link to comment https://forums.phpfreaks.com/topic/148268-solved-phone-regex/#findComment-778493 Share on other sites More sharing options...
Boo-urns Posted March 6, 2009 Author Share Posted March 6, 2009 Don't those regexes not replace as well? Link to comment https://forums.phpfreaks.com/topic/148268-solved-phone-regex/#findComment-778504 Share on other sites More sharing options...
.josh Posted March 7, 2009 Share Posted March 7, 2009 If you are sure that will be the format 100% of the time... $number="(381) 323-4567"; $number = preg_replace('~\((\d{3})\) (\d{3})-(\d{4})~','$1 $2 $3',$number); If you are not sure that will be the format 100% of the time... $number="(381) 323-4567"; $number = preg_replace('~[-(). ]~','',$number); $number = substr($number,0,3) . " " . substr($number,3,3) . " " . substr($number,-4); Link to comment https://forums.phpfreaks.com/topic/148268-solved-phone-regex/#findComment-778660 Share on other sites More sharing options...
Boo-urns Posted March 9, 2009 Author Share Posted March 9, 2009 Thanks a lot Crayon Violent it worked perfectly! Link to comment https://forums.phpfreaks.com/topic/148268-solved-phone-regex/#findComment-780312 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.