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
Ken S (OLD ACCOUNT)Ken S (OLD ACCOUNT) 

Validation rule to search and replace entered text (string) in text field

Can someone tell me how to write a validation rule to search and replace entered text with other text? For example, if the string " Street, " exists in an address field, it should replace it with " St ". Likewise, replace " West " with " W ".  So for example "129 West 81st Street, Apt 2" will become the standarsized USPS formatted "129 W 81st St Apt 2".

(We are currently not on the Household Account model yet so I can use address Google/Cicero/SmartyStreets verificaion APIs and am trying to find some ways to keep our address data somewhat clean in the meantime... Alternative suggestions welcome.)
Raj VakatiRaj Vakati
The validation rule is to prevent the enter bad data formate .. But it is not let you update the data ??

Do you want to write a workflow or process builder to replace the data ?? 

Can you explain you want validation to prevent or workflow to update the data 
Ken S (OLD ACCOUNT)Ken S (OLD ACCOUNT)
Ah, yes, i see. Perhaps this needs to be a combination of validation and workflow rules, or process builder steps, then?  Could you recommend the steps and best approach?  To enforce validatation rules before record save, but then also "correct" or modify the data entered after save.
Raj VakatiRaj Vakati
The is the best approach in my opinion .. 

Write a validation rule to prevent .. you can use some regex to format the USPS formate 



Use this reg exp 
 
/\s+(\\d{2,5}\s+)(?![a|p]m\b)(([a-zA-Z|\s+]{1,5}){1,2})?([\s|\,|.]+)?(([a-zA-Z|\s+]{1,30}){1,4})(court|ct|street|st|drive|dr|lane|ln|road|rd|blvd)([\s|\,|.|\;]+)?(([a-zA-Z|\s+]{1,30}){1,2})([\s|\,|.]+)?\b(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|GU|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NC|ND|NE|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VI|VT|WA|WI|WV|WY)([\s|\,|.]+)?(\s+\d{5})?([\s|\,|.]+)/i