Skip to content

Tt number

A Trouble Ticket number.

validate_tt_number(tt_number)

Validate a string to match a specific pattern.

This method checks if the input string is exactly 7 digits. Alternatively, the ticket number format of the old system is also allowd: these start with 'TT#' and are followed by exactly 16 digits.

Parameters:

Name Type Description Default
tt_number str

The TT number as string to validate

required

Returns:

Type Description
str

The TT number string if TT number match was successful.

Source code in gso/utils/types/tt_number.py
def validate_tt_number(tt_number: str) -> str:
    """Validate a string to match a specific pattern.

    This method checks if the input string is exactly 7 digits.
    Alternatively, the ticket number format of the old system is also allowd:
    these start with 'TT#' and are followed by exactly 16 digits.

    Args:
        tt_number: The TT number as string to validate

    Returns:
        The TT number string if TT number match was successful.

    Raises:
        ValueError if the string is not valid.
    """
    pattern = r"^TT#\d{16}$|^\d{7}$"
    if not bool(re.match(pattern, tt_number)):
        err_msg = "A valid ticket number must be exactly 7 digits."
        raise ValueError(err_msg)

    return tt_number