""" Utility functions shared across the EAMCO Authorize service. """ import re def sanitize_input(text, max_len, allow_spaces=False, is_zip=False): """ Sanitize input string by removing invalid characters. Args: text: Input text/number/value max_len: Maximum length of the output string allow_spaces: If True, allows spaces in the output is_zip: If True, allows hyphens (for ZIP+4) Returns: Sanitized string truncated to max_len """ if not text: return "" if is_zip: pattern = r'[^a-zA-Z0-9-]' else: pattern = r'[^a-zA-Z0-9]' if not allow_spaces else r'[^a-zA-Z0-9\s]' sanitized = re.sub(pattern, '', str(text)) return sanitized.strip()[:max_len]