We generate a unique service phone number for users and it is generated in the following format: 11234567890. I am looking to use a program token to reformat it in the following layout: 1-123-456-7890. I found some code here from @SanfordWhiteman blog (https://blog.teknkl.com/velocity-reformat-phone-numbers-remove-punctuation/) but I can't seem to get the code to populate correct. I'm positive I am missing something. Any thoughts? Thank you in advance!
Code being used currently:
#set( $originalPhone = $lead.servicePhoneNumber )
## remove non-digits
#set( $unpunctuatedPhone = $unprefixedPhone.replaceAll("\D","") )
## format as 1-123-456-7890
#set( $displayPhone = $unpunctuatedPhone.replaceAll("(\d{1})(\d{3})(\d{3})(\d{4})","$1\-$2\-$3\-$4") )
## raw form in href, friendly form in text
<a class="mktNoTrack" href="tel:+1${unpunctuatedPhone}">${displayPhone}</a>
Solved! Go to Solution.
Remember to use the Syntax Highlighter (“Insert/Edit Code Sample”) when inserting code so it’s readable:
I edited your post this time.
Looks like you’re using the wrong variable name. Should be $originalPhone
, not $unprefixedPhone
, on line 3:
#set( $originalPhone = $lead.servicePhoneNumber )
## remove non-digits
#set( $unpunctuatedPhone = $originalPhone.replaceAll("\D","") )
## format as 1-123-456-7890
#set( $displayPhone = $unpunctuatedPhone.replaceAll("(\d{1})(\d{3})(\d{3})(\d{4})","$1\-$2\-$3\-$4") )
## raw form in href, friendly form in text
<a class="mktNoTrack" href="tel:+1${unpunctuatedPhone}">${displayPhone}</a>
Remember to use the Syntax Highlighter (“Insert/Edit Code Sample”) when inserting code so it’s readable:
I edited your post this time.
Looks like you’re using the wrong variable name. Should be $originalPhone
, not $unprefixedPhone
, on line 3:
#set( $originalPhone = $lead.servicePhoneNumber )
## remove non-digits
#set( $unpunctuatedPhone = $originalPhone.replaceAll("\D","") )
## format as 1-123-456-7890
#set( $displayPhone = $unpunctuatedPhone.replaceAll("(\d{1})(\d{3})(\d{3})(\d{4})","$1\-$2\-$3\-$4") )
## raw form in href, friendly form in text
<a class="mktNoTrack" href="tel:+1${unpunctuatedPhone}">${displayPhone}</a>