Skip to content

Instantly share code, notes, and snippets.

@raystorm
Last active December 24, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raystorm/6801513 to your computer and use it in GitHub Desktop.
Save raystorm/6801513 to your computer and use it in GitHub Desktop.
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