import re


def validate_domain(domain):
    """ Validate a domain name.
    """
    if len(domain) > 255 or len(domain) == 0:
        return False
    if domain[-1] == '.':
        domain = domain[:-1]
    allowed = re.compile(
        r'\A([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\Z', re.IGNORECASE
    )
    return allowed.match(domain)