function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jishan royjishan roy 

10 digit Phone number format is (xxx) xxx-xxxx but i want less than 10 digit then also format should be work

Hii all,

can anyone help me out of this question?

10 digit Phone number format is (xxx) xxx-xxxx but i want less than 10 digit then also format should be work. If suppose my phone field have 9 digit 123456789 then i want this type of format like (123) 456-789
is it possible? it should be work between 7 number.
SwethaSwetha (Salesforce Developers) 
HI Jishan,
You could create a formula field with text as return type and reference the phone field on your object like below 
 
IF(
    NOT(ISBLANK(Phone)),
    IF(
        LEN(Phone) >= 7,
        "(" & LEFT(Phone,3) & ") " & MID(Phone,4,3) & "-" & RIGHT(Phone, LEN(Phone)-6),
        Phone
    ),
    ""
)

 

If this information helps, please mark the answer as best. Thank you

jishan royjishan roy
HI Swetha,
its worked good but the thing is when i edited phone number suppose in phone field had 7 digit number so its look like (123) 456-7
like this and when i update the phone number and i add one more digit then also its changed all format and look like ((12) 3) -456-78 like this i want when i edited then also show (123) 456-78 like this is it possible?

thanks in advance!
SwethaSwetha (Salesforce Developers) 
@Jishan, Thanks for pointing this testcase. Try this updated formula
IF(
    NOT(ISBLANK(Phone)),
    IF(
        LEN(Phone) >= 7 && LEN(Phone) <= 10,
        "(" & LEFT(Phone,3) & ") " & MID(Phone,4,3) & "-" & RIGHT(Phone, LEN(Phone)-6),
        IF(
            LEN(Phone) < 7,
            Phone,
            LEFT("(" & LEFT(Phone,3) & ") " & MID(Phone,4,3) & "-" & RIGHT(Phone, LEN(Phone)-6),14)
        )
    ),
    ""
)

I've tested in my org and it works as expected even after editing

If this information helps, please mark the answer as best. Thank you
jishan royjishan roy
HI Swetha,
above formula is not properly working on update i use this formula on flow builder.
SwethaSwetha (Salesforce Developers) 
The above works for the regular formula field. What do you see as an error incase of the formula on the flow builder?  

Thanks

 
jishan royjishan roy
hello,

IF( NOT(ISBLANK(Phone)), IF( LEN(Phone) >= 7 && LEN(Phone) <= 10, "(" & LEFT(Phone,3) & ") " & MID(Phone,4,3) & "-" & RIGHT(Phone, LEN(Phone)-6), IF( LEN(Phone) < 7, Phone, LEFT("(" & LEFT(Phone,3) & ") " & MID(Phone,4,3) & "-" & RIGHT(Phone, LEN(Phone)-6),14) ) ), "" )

for this formula i want greater than 10 digit on that format is it possible?