def nif_nie_validation(doi, number_by_letter, special_cases):
    """
    Validate if the doi is a NIF or a NIE.
    :param doi: DOI to validate.
    :return: boolean if it's valid.
    """
    doi = doi.upper()
    if doi in special_cases:
        return False
    table = 'TRWAGMYFPDXBNJZSQVHLCKE'
    if len(doi) != 9:
        return False
    control = doi[8]
    numbers = number_by_letter.get(doi[0], doi[0]) + doi[1:8]
    return numbers.isdigit() and control == table[int(numbers) % 23]
