Spaces:
Sleeping
Sleeping
| """ | |
| Validation utilities for model card inputs | |
| """ | |
| import re | |
| def validate_mmcid(mmcid): | |
| """ | |
| Validate MMCID format: DF-MC-YYYY-NNN | |
| Args: | |
| mmcid: String to validate | |
| Returns: | |
| Boolean indicating if format is valid | |
| Examples: | |
| DF-MC-2025-001 β | |
| DF-MC-2024-123 β | |
| df-mc-2025-001 β (wrong case) | |
| DF-MC-25-001 β (year must be 4 digits) | |
| """ | |
| if not mmcid: | |
| return True # Empty is valid (optional field) | |
| pattern = r'^DF-MC-\d{4}-\d{3}$' | |
| return bool(re.match(pattern, mmcid)) | |
| def validate_controlled_vocab_selection(selections, max_items=3): | |
| """ | |
| Validate that multi-select doesn't exceed max items | |
| Args: | |
| selections: List of selected items | |
| max_items: Maximum allowed selections (default 3) | |
| Returns: | |
| Tuple of (is_valid, error_message) | |
| """ | |
| if not selections: | |
| return True, None | |
| if len(selections) > max_items: | |
| return False, f"Please select no more than {max_items} items" | |
| return True, None |