0

I have a form where the user types a day (number between 1 and 31) and then selects a month from a list and then types a year.

The problem is that when a date such as (31 February) will throw the following error:

day is out of range for month

Is there a way I can check if the day is valid for that month (and year if it is a leap year) in the form?

drew
  • 771
  • 1
  • 4
  • 11

1 Answers1

2

If you use django Forms check SelectDateWidget

btw, why don't you want to catch such errors and show above your form in other words (if you allow to choose and submit 31 and 'February')?

Satevg
  • 1,601
  • 2
  • 16
  • 23
  • That is what I am trying to do, I want the field to show as invalid if the date isnt correct. – drew Mar 07 '17 at 14:58
  • @andrew_ Do you use django forms or plain html form? If first, then check http://stackoverflow.com/a/14647770/2614426 – Satevg Mar 07 '17 at 15:06
  • I am using django forms. I have now used SelectDateWidget as suggested and this seems to do the trick. thanks – drew Mar 07 '17 at 15:07