I am new to python, so obviously as well to using regex. I am just curious if it is possible to see if a number is inputted before other numbers in a string?
What this function(def checkzero) should be doing is checking to see if 0 is inputted before another number, and if it is then return True (For invalid)
import string
import re
plate_pattern = re.compile('\D*\d*')
def main():
plate = input("Plate: ")
tests = [exclusions, platecheck, checkzero]
invalid = any(test(plate) for test in tests)
if invalid:
print("Invalid \nNo numbers in the start/middle of the plate, first number may not be 0. \nNo punctuation allowed.\nPlate must be between 2-6 characters.")
else:
print("Valid")
def exclusions(s):
if any(c in string.punctuation for c in s):
return True
return len(s) > 6 or len(s) < 2
def platecheck(s):
return not plate_pattern.fullmatch(s)
def checkzero(s):
# Not sure how to go about creating the function to check if zero is inputted before other numbers.
pass
main()
Example of Input/Output:
Input:
test02
Output:
Invalid
...
Input:
test20
Output:
Valid