Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

using regex in replaceAll to replace multiple char in one go

Asked by Freeman Pacifico Apr 22, 2021 2.5K views 1 answer
Share

About this question

I have a phone number that i need to convert to a valid format to be send to a webservice validator. The phone number should be 10 char long and should contains only digits. For instance, I should convert +567 231 34 34 to 5672313434 (567)231-34-34 to 5672313434 before sending I have the solution which does the replacement in apex :

String t = '+571 567 65 77'; String r = t.replaceAll('\(',''); r = r.replaceAll('\)',''); r = r.replaceAll('-',''); r = r.replaceAll('\+',''); r = r.replaceAll('\s',''); system.debug('## final result is :' + r);

Can I obtain the result in a single line?

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.