For your first check
import string
if len(name) > 10 or any(l not in string.ascii_letters for l in name):
# reject
for your second
if cls not in ["5A1", "5A2", ...]:
# reject
or you could do something a bit more complex:
def validate_class(cls):
if (len(cls) != 3 or
int(cls[0]) not in [5, 6] or
cls[1] not in ["A", "B", "C"] or
int(cls[2]) not in [1, 2]):
return False
return True
This expresses a more general rule for what a valid class cls
is.