File size: 1,083 Bytes
fc0be42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
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