Plugin

Archived
Forum
(read-only)

CE String

ExpressionEngine 2, ExpressionEngine 3

Back to this add-on's main page
View Other Add-ons From Causing Effect

     

auto_link Phone Numbers

Feature (Resolved)

MajesticIX
MajesticIX

Not sure how difficult this would be to implement, but to be able to auto_link phone numbers would be fan-freaking-tastic:

585-555-1212

<a >585-555-1212</a>

Could seed some $ if interested.

Causing Effect - Aaron Waldon
# 1
Developer
Causing Effect - Aaron Waldon

Hi MajesticIX!

I think this would really only be useful on mobile only sites. Otherwise, the phone links would be dead/broken on desktop (or non-mobile devices). Some mobile devices already handle the phone number linking natively, like the iPad and iPhone.

If you did want to add this for mobile devices, it looks like the best format is:

<a href="tel:1-408-555-5555">1-408-555-5555</a

Something like this could probably work:

{exp:ce_str:ing preg_rep='.*(\\d{3})[^\\d]*(\\d{3})[^\\d]*(\\d{4}).*|<a href="tel:1-$1-$2-$3">($1) $2-$3</a>'}
(111222-3333
((111222-3333
1112223333
111 222
-3333
111
-222-3333
(111)2223333
+11234567890
1
-8002353551
123
-456-7890   -Hello!
+
1234567890
{
/exp:ce_str:ing} 

Which returns:

<a href="tel:1-111-222-3333">(111222-3333</a>
<
a href="tel:1-333-111-2223">(333111-2223</a>
<
a href="tel:1-111-222-3333">(111222-3333</a>
<
a href="tel:1-333-111-2223">(333111-2223</a>
<
a href="tel:1-123-456-7890">(123456-7890</a>
<
a href="tel:1-800-235-3551">(800235-3551</a>
<
a href="tel:1-123-456-7890">(123456-7890</a>
<
a href="tel:1-123-456-7890">(123456-7890</a

I got part of that regex from this example. Changes would probably need to be made in order to make that regex awesome though. It just assumes a US international prefix right now.

MajesticIX
# 2
MajesticIX

Cool, I’ll see how that works. Thanks for the prompt response!

Vaughn D. Taylor
# 3
Vaughn D. Taylor

Has this been tested? I’ve tried the example, and I get no replacement.

This is my input: 5556669999

And this is my desired output: 555-666-9999

This is my first test:

{exp:ce_str:ing preg_rep='.*(/^(\\\\\\\\\\\\\\\\d{3})(\\\\\\\\\\\\\\\\d{3})(\\\\\\\\\\\\\\\\d{4})$/).*|$1-$2-$3'}{phone_number}{/exp:ce_str:ing} 

Which returns: 5556669999

I’ve determined that CE String is working, but regex does not seem to be working. This test:

{exp:ce_str:ing preg_rep='5|FIVE'}{doctors_phone_numbers:phone_1}{/exp:ce_str:ing} 

Returns: FIVEFIVEFIVE6669999

EDIT: I tried it as shown in the example above, and it’s still not working:

{exp:ce_str:ing preg_rep='.*(\\\\\\\\\\\\\\\\d{3})[^\\\\\\\\\\\\\\\\d]*(\\\\\\\\\\\\\\\\d{3})[^\\\\\\\\\\\\\\\\d]*(\\\\\\\\\\\\\\\\d{4}).*|($1) $2-$3'}{phone_number}{/exp:ce_str:ing} 

Still returns: 5556669999

EDIT AGAIN:

Doh, I just discovered what the issue is! In the example above, there’s an extra “\” escape. I noticed that an extra escape was added to my post as well. It’s the code formatting that’s messing up the example. So there should only be one escape character before each d above - like this ^\d