How to remove all non numbers using Apex in Salesforce?

How to remove all non numbers using Apex in Salesforce?

Sample code:


  1. String invalidNumbers = ‘[^0-9]’;  
  2. String str = ‘abcd123456789xyz’;  
  3. system.debug( ‘Only numbers – ‘ + str.replaceAll( invalidNumbers,  ) );  



Output:

Leave a Reply