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

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ddf0232b-63e1-4d80-aea9-a03813f387ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to