import re from typing import Optional, Any def normalizar_telefono_con_plus(texto: Any) -> Optional[str]: """ Mantiene '+' si está al principio y el resto sólo dígitos. - ' (+34) 600-123-456 ' -> '+34600123456' - '620 61 24 91 Tamara' -> '620612491' - None o sin dígitos -> None """ if texto is None: return None s = str(texto).strip() keep_plus = s.startswith("+") # Quitar todo lo que NO sea dígito digits = re.sub(r"\D", "", s) if not digits: return None return ("+" if keep_plus else "") + digits