In my PHP code I am able to strip hyphens and parenthesis from phone numbers by using
preg_replace('/\D+/', "", $cell);
OR
preg_replace('/[ )(.-]/', "", $cell);
Two questions:
(1) Which of the above formats is best for removing ALL unwanted characters (,-,.,etc, as well as alpha characters.
(2) I also need to remove the leading “1” (country code for USA) if entered by user
There are many ways to remove non-digits, but I would suggest using whatever method make the most sense to you, that is, which one seems most intuitive and easy to understand when you look at the code again months from now.
Your
\Dworks just fine but adding^1will also replace the leading1you’re looking for.