File size: 660 Bytes
f0f6114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Shared validators used across the codebase.
"""

import re

COMPANY_ID_PATTERN = re.compile(r"^[a-zA-Z0-9_\-]{3,64}$")


def validate_company_id(company_id: str) -> str:
    """
    Validate and sanitize a company_id.
    Raises ValueError if invalid.
    Returns the cleaned company_id.
    """
    if not company_id:
        raise ValueError("company_id cannot be empty.")

    company_id = company_id.strip()

    if not COMPANY_ID_PATTERN.match(company_id):
        raise ValueError(
            f"Invalid company_id: '{company_id}'. "
            "Only letters, numbers, underscores, and hyphens allowed (3-64 chars)."
        )

    return company_id