pattern = re.compile(ur'^(?=\d{2}([\/])\d{2}\1\d{4}$)(?:0[1-9]|1\d|[2][0-8]|29(?!.02.(?!(?!(?:[02468][1-35-79]|[13579][0-13-57-9])00)\d{2}(?:[02468][048]|[13579][26])))|30(?!.02)|31(?=.(?:0[13578]|10|12))).(?:0[1-9]|1[012]).\d{4}$')
goodmatch = re.match(pattern, date_from)
# raise NameError(goodmatch)
if goodmatch:
pass
else:
date_from_error = "Incorrect input, must be dd/mm/yyy format"
goodmatch seems to always be None.
I tested the regex at regex101 abd it works with test data like 27/10/2015
date_from is a date object so I also tried converting it to a string like
pattern = re.compile(ur'^(?=\d{2}([\/])\d{2}\1\d{4}$)(?:0[1-9]|1\d|[2][0-8]|29(?!.02.(?!(?!(?:[02468][1-35-79]|[13579][0-13-57-9])00)\d{2}(?:[02468][048]|[13579][26])))|30(?!.02)|31(?=.(?:0[13578]|10|12))).(?:0[1-9]|1[012]).\d{4}$')
str_date = str(date_from)
goodmatch = re.match(pattern, str_date)
if goodmatch:
pass
else:
date_from_error = "Incorrect input, must be dd/mm/yyy format"
Any help understanding and getting it to do the job defined in the if much appreciated