Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Strip phone number formatting
* removes any non-digit character from the phone number
* @param phoneNumber number to be de-formatted
* @return phone number digits
protected String clearFormatting(String phoneNumber)
StringBuilder out = new StringBuilder(phoneNumber.length());
int lower = ((int)'0'-1);
int upper = ((int)'9'+1);
for (char c : phoneNumber.toCharArray() )
{ //only collect the digits
if ( lower < c && upper > c ) { out.append(c); }
return out.toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment