A Text field to be saved with Spaces - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Tanvi BhatnagarTanvi Bhatnagar 

A Text field to be saved with Spaces

Hi Everyone

I have a requirement where there is a Text field and we want that when the users enter data in the field it is auto saved with spaces.
Eg: 11 111 111 111
I have tried using Validation rules but it does not fulfil our requirement. Our requirement is either the field will have auto spaces when the users are entering the data (Like Mask feature in Form Assembly) or once the users save the recod the data in the field is converted with spaces.

Thanks,
Tanvi
Best Answer chosen by Tanvi Bhatnagar
Tanvi BhatnagarTanvi Bhatnagar

I was able to work it out by using a Validation rule 
AND(
NOT(ISBLANK(Field__c)),
NOT (REGEX(Field__c,"[0-9]{2}\\s{0,1}[0-9]{3}\\s{0,1}[0-9]{3}\\s{0,1}[0-9] {3}\\s{0,1}[0-9]"))
)

And a WorkFlow Field Update:

LEFT(SUBSTITUTE(Field__c, ' ', ''),2)
&
' '
&
LEFT(RIGHT(SUBSTITUTE(Field__c, ' ', ''),6),3)
&
' '
&
LEFT(RIGHT(SUBSTITUTE(Field__c, ' ', ''),6),3)
&
' '
&
RIGHT(TRIM(Field__c),3)