seguro-app / appClientes /validators.py
Facundo
opencode-2
936e949
Raw
History Blame Contribute Delete
847 Bytes
import re
import unicodedata
POLIZA_PATTERN = re.compile(r"[A-Z0-9\-]{4,30}")
def normalize_text(value: str) -> str:
return " ".join((value or "").strip().split())
def normalize_for_search(value: str) -> str:
base = normalize_text(value).casefold()
return "".join(
ch for ch in unicodedata.normalize("NFD", base)
if unicodedata.category(ch) != "Mn"
)
def normalize_poliza(value: str) -> str:
return normalize_text(value).upper()
def is_valid_poliza(value: str) -> bool:
return bool(POLIZA_PATTERN.fullmatch(value or ""))
def validate_contacto(value: str) -> bool:
cleaned = normalize_text(value)
if not cleaned:
return False
if "@" in cleaned:
return bool(re.fullmatch(r"[^@\s]+@[^@\s]+\.[^@\s]+", cleaned))
return bool(re.fullmatch(r"[\d\s+\-()]{6,}", cleaned))