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! Quote 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 Quote 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? Quote 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); Quote 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! Quote Link to comment https://forums.phpfreaks.com/topic/148268-solved-phone-regex/#findComment-780312 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.