urmi-ai/backend/app/sender_validators.py
2026-10-02 11:22:40 +05:30

38 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
SENDER_ID_PATTERN = re.compile(r"^[A-Z0-9]{3,11}$")
DLT_ENTITY_PATTERN = re.compile(r"^\d{12,25}$")
def normalize_sender_id(value: str) -> str:
return value.strip().upper()
def validate_sender_id(value: str) -> str:
sender_id = normalize_sender_id(value)
if not SENDER_ID_PATTERN.match(sender_id):
raise ValueError("Sender ID must be 3–11 uppercase letters or numbers")
return sender_id
def validate_sender_type(value: str) -> str:
normalized = value.strip().lower()
if normalized not in {"promotional", "transactional"}:
raise ValueError("Type must be promotional or transactional")
return normalized
def validate_purpose(value: str) -> str:
purpose = value.strip()
if len(purpose) < 10:
raise ValueError("Purpose must be at least 10 characters")
if len(purpose) > 500:
raise ValueError("Purpose must be 500 characters or fewer")
return purpose
def validate_dlt_entity_id(value: str) -> str:
entity_id = value.strip()
if not DLT_ENTITY_PATTERN.match(entity_id):
raise ValueError("DLT Entity ID must be 12–25 digits")
return entity_id