Reputation: 17
Python Code
Scrubbing and reformatting data is a real world problem in computer science, it is the process of taking in a human input that may be in the incorrect format and cleaning it up to put it in a standard format. How can I write a program that asks someone to enter a phone number and then returns that phone number in a standard format if possible otherwise giving an error.
Examples:
Please enter a phone number including area code: 607-8675309
(607)867-5309
Please enter a phone number including area code: 16078675309
(607)867-5309
Please enter a phone number including area code: (607) Jenny I got your number, I need to make you mine, Jenny don't change your number, 8675309
(607)867-5309
Upvotes: 0
Views: 834
Reputation: 30111
You need to clean the input fields and check against your desired output and return the a message accordingly. Python web frameworks like Django, Web2py, Flask exists to precisely help with these types of problems.
Upvotes: 1
Reputation: 10363
I would suggest to cleanup/validate phone number formatting using regular expressions.
Upvotes: 0