I have a simple app that allows the user to push a button that brings up the list of contacts. They select the contact and the application then puts the phone number into an edit text control. This all works like a charm.
However, I notice that the phone number that is retrieved has 'punctuation' marks in it: 123.456.7890 or 123-456-7890 is returned verbatim with the dots and dashes included.
Is there a simple way to s开发者_开发问答trip out non-numeric entry before displaying back to the user?
You should be able to manipulate the string using standard Java String functions to remove non numbers.
i.e.
myString.replaceAll("\D", "");
\D is a regex that should match anything that isn't a digit. See Pattern docs.
replaceAll will replace all instances of the regex with whatever you provide as the second param.
精彩评论