How do I format a phone number so that when I receive a number during user registration, formatting occurs immediately?
I need that after registering a user, his phone number (and he can enter it as 8990000000 and 79000000000 or so +79800000000 and so on) is converted in this format tel: +7-900-821-88-99
I tried to do it like
def formatting_number(phone): NUM_RE = re.compile((r".*(\d).*(\d).*(\d).*(\d).*(\d).*(\d).*(\d).*(\d).*(\d).*(\d).*")) phone['Tel'] = phone['Tel'].apply(lambda x: "tel:" + "+7" ''.join(NUM_RE.match(x).groups()))
but i think it won't work
All what i do it's for FastAPI project
I'd do custom logic in several steps, for example collect all digits, check if there is
7at the beginning etc.:Prints: