2

I need the RegEX to remove all special characters and spaces (667) 788-9900, I want to be 6677889900

And it should work for (667) 788, then I should get 667788.

3
replaceAll('\\D','');

This will remove anything that is not a digit from the phone number.

Credits - https://developer.salesforce.com/forums/?id=906F00000008yP9IAI

1
String str = '(667) 788';
String newStr = str.replaceAll('\\D', '');
System.debug('Final : '+newStr);

Done !!

  • 1
    This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review – Martin Lezer Apr 13 '17 at 12:34
  • 1
    @Martine - This works fine. I have already implemented this in my project. – user4567570 Apr 13 '17 at 17:08
  • You're just answering the same solution than @NikhilKhivansara. – Martin Lezer Apr 14 '17 at 7:00
  • 1
    To be fair, their answer was posted in the same minute. Also, this one compiles, not so sure about the other one. – Nielsm Oct 3 '17 at 14:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.