I write a code to verify the license plates of cars and there are some conditions to achieve this purpose:
- The first letter should not be
0 - It shouldn't have any numbers between letters(
AAA12is ok, butAA2AAAis not.) - It should start with two letters
- The count of letters must be between 2 - 6 letters
def is_valid(s):
s = s.lower()
if len(s) >= 2 and len(s) <= 6 and s[0] != 0 and s[0:2].isalpha():
if s.isalpha():
return True
elif s.isalnum():
for sq in s.split():
for w in sq:
if w.isdigit():
x = sq.index(w)
try:
if s[w:].isalpha():
return False
else:
return True
except:
return True
So my code is doing most of these conditions in a right way, but when I enter e.g. HL23P2, I expect to get False but it returns True.
Why does it return False? because I can't have numbers between letters only it is allowed when its like e.g. HEL23.
But how can I detect numbers between letters?