Last active
December 24, 2015 12:59
-
-
Save raystorm/6801513 to your computer and use it in GitHub Desktop.
Strip phone number formatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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