There is a slight flaw in the rz answer as it does not account for leap years.
If someone was born on January 1, 1994, then checking the date of birth mentioned in the rz answer will calculate them as December 18 to December 28, 2011.
Here's an alternative version that takes into account leap years:
from datetime import date from registration.forms import RegistrationForm class DOBRegistrationForm(RegistrationForm): date_of_birth = forms.DateField() def clean_date_of_birth(self): dob = self.cleaned_data['date_of_birth'] today = date.today() if (dob.year + 18, dob.month, bod.day) > (today.year, today.month, today.day): raise forms.ValidationError('Must be at least 18 years old to register') return dob
source share