Function - Irish Landline/Mobile Clean-up

PHOTO EMBED

Thu Mar 11 2021 15:19:13 GMT+0000 (Coordinated Universal Time)

Saved by @stephenb30 #python

import re

def Phone_Number(s):
    s = str(s)
    s = s.translate(str.maketrans("", "", ",.-'\"():|*`;+/!&?$°@#"))
    s.replace('\.0', '')
    s = re.sub('\D', '', s)
    Prefixes = ["353", "00353", "0353", "00", "01" , "021", "022", "023", "024", "025", "026",
                "027", "028", "029", "0402", "0404", "041", "042", "043", "044", "045", "046",
                "047", "048", "049", "0504", "0505", "051", "052", "053", "056", "057", "058", 
                "059", "061", "062", "063", "064", "064", "065", "066", "067", "068", "069",
                "071", "074", "090", "091", "093", "094", "095", "096", "097", "098", "099" ]
    for n in Prefixes:
        if s.startswith(n):
            s = s.replace(n,"")
    if s.startswith('8') == True and len(s) == 9:
      s = '0' +s
    if len(s) < 6:
        s = ""
    if len(s) > 10:
        s = ""
    Contains = ['00000', '123456']
    if any(c in s for c in Contains):
        s = ""     
    return s
content_copyCOPY