by tdavis · 18y ago · 0 comments
Here's a single line of python that removes any character that isn't a digit from the string "s":
re.sub(r'[^\d]', '', s)
Wow, that was almost too easy. Now the user can put spaces, dashes, periods, underscores... who cares! Oh, and if they put in the CSV code or something at the end... re.sub(r'[^\d]', '', s)[0:16]
A single line should cover 99% of the problems the user can create. Compliment it by giving an example of how the number should be input and... done.