<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
0D54z000070QBvuCAGOkta Classic EngineSingle Sign-OnAnswered2021-06-07T16:48:34.000Z2021-06-07T16:24:07.000Z2021-06-07T16:48:34.000Z

JordanJ.26599 (Customer) asked a question.

Custom Expression - Add Hyphens to Phone Number

I have a service provider SSO integration that is requiring the phone number attribute come through the assertion in format XXX-XXX-XXXX. Currently, Active Directory is our Profile Master and the format is country code, then 10 digit phone number, like +15555555555. We need to create an attribute for this SP that takes the phone number and changes it to the support format like 555-555-5555 (no + and no country code, add hyphens). So far I have this which works to remove the + and the country code-

 

String.replace(user.primaryPhone, "+1","")

Anyone have any suggestion on how to add the hyphens as expected?


  • JordanJ.26599 (Customer)

    Well I played around enough and found something that will work for me. Here it is if anyone else comes across this same sort of question-

     

    String.substring(user.primaryPhone, 2, 5)+"-" + String.substring(user.primaryPhone, 5, 8)+"-" + String.substring(user.primaryPhone, 8, 12)

     

    Since my AD format is +155555555555, instead of removing the +1 for country code, I just only read in the characters I want and break them apart by adding hyphens between. I'm sure there are better ways and I'm all ears but this will work for me.

    Expand Post
    Selected as Best
  • JordanJ.26599 (Customer)

    Well I played around enough and found something that will work for me. Here it is if anyone else comes across this same sort of question-

     

    String.substring(user.primaryPhone, 2, 5)+"-" + String.substring(user.primaryPhone, 5, 8)+"-" + String.substring(user.primaryPhone, 8, 12)

     

    Since my AD format is +155555555555, instead of removing the +1 for country code, I just only read in the characters I want and break them apart by adding hyphens between. I'm sure there are better ways and I'm all ears but this will work for me.

    Expand Post
    Selected as Best
This question is closed.
Loading
Custom Expression - Add Hyphens to Phone Number