1

I am using the Field Validation module to validate a date field that will contain a user's birthday. I want to make sure the person is 18 years of age or older. Here are the settings I was thinking of using in my validation rule. Are these correct?

Column: value

Minimum Date: now - 18 year

1
  • sure as long as their not a leap year baby.
    – tenken
    Aug 4, 2013 at 5:07

2 Answers 2

3

Depending on your requirements, Field Validation can be a good approach. It's simple to set up, but one potential issue is that if this field is something that the user can edit, they can easily modify their birthday if the form submission is rejected.

Often this is OK, but for my site I needed to actually block users who were under 18, so I did the following. I have a required date field, birthday, on the user registration form.

Then, I added a computed field, age, to calculate the age based on the value of the date field, birthday. For sample PHP, you can see this Stack Overflow answer. This is a way that you can take into account leap years, etc.

Then, I added a rule:

Event After saving a new user account

Condition Data to compare: Age less than 18.

Actions Block user

The advantage of doing it this way is that if a user registers with a birthday under 18, their e-mail address will be blocked from registering again. Of course, this may or may not be necessary for your case, but I'm just putting it out there because other sites may have such a requirement.

1
0

Date Restrictions is useful to acomplish this with no coding. Enable date_restrictions_minmax submodule, and configure your date field to set a minimum valid date of 18 years.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.