import re


def _validate_pattern(pattern):
    """Check that regex pattern conforms to type and format requirements."""

    if not isinstance(pattern, str):
        raise TypeError("Pattern must be a string.")

    if pattern.count("(#") != 1:
        raise ValueError("Pattern must contain exactly one anchor group.")

    if pattern.startswith(" ") or pattern.endswith(" "):
        raise ValueError("Pattern cannot start or end with a whitespace.")

    if 2 * " " in pattern:
        raise ValueError("Pattern cannot contain consecutive whitespaces.")

    return re.compile(pattern)