12 lines
320 B
Python
12 lines
320 B
Python
import re
|
|
|
|
def normalize(number):
|
|
phone_regex = re.compile(r'\+?1?.?.?([2-9]\d{2}).?.?(\d{3}).?([2-9][0-8]\d{2}$)')
|
|
|
|
tmp = phone_regex.match(number)
|
|
if(tmp):
|
|
return '1' + '-' + tmp.group(1) + '-' + tmp.group(2) + '-' + tmp.group(3)
|
|
else: raise ValueError('Ungültige Telefonnummer')
|
|
|
|
|