Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8284537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:08:38+00:00 2026-06-08T11:08:38+00:00

I have the following validation rule in my model: ‘dob’ => array( ‘required’ =>

  • 0

I have the following validation rule in my model:

'dob' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'Date of Birth is required'
            ),
            'age' => array(
                'rule' => array('comparison', '>=', 13),
                'message' => 'You must be over 13 years old'
            )
        )

What I’m trying to achieve is validate that the user is over 13 years old…

The date is created like so:

<?php echo $this->Form->input('Profile.dob', array('label' => 'Date of Birth'
                                        , 'dateFormat' => 'DMY'
                                        , 'minYear' => date('Y') - 110
                                        , 'maxYear' => date('Y') - 13)); ?>

How do I do it though? As the saved data is a date and not a whole number so my comparison won’t work… Looking for simplest solution here without replying on plugins or other external assets and just some simple code if possible.

Thanks.

EDIT: So based on the comments below I have added:

public function checkDOB($check) {
        return strtotime($check['dob']) < strtotime();
    }

But what do I put in the strtotime to check the age is above or EQUAL to 13?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:08:40+00:00Added an answer on June 8, 2026 at 11:08 am

    Create a custom validation rule in your model:

    public function checkOver13($check) {
      $bday = strtotime($check['dob']);
      if (time() < strtotime('+13 years', $bday)) return false;
      return true;
    }
    

    This uses a neat feature of strtotime that lets you easily do date calculations on a particular date.

    To use the rule:

    'dob' => array(
      'age' => array(
        'rule' => 'checkOver13',
        'message' => 'You must be over 13 years old'
      )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following validation in a model: validates_length_of :description, :minimum => 2, :on
I have the following validation code processed for my User Model. It works good
I am using jQuery Validation Plugin (http://bassistance.de/jquery-plugins/jquery-plugin-validation/) I have wrote following rule jQuery.validator.addMethod(valueNotEquals, function(value,
I'm using the jQuery Validation plug-in. I have overwritten the required rule since mine
I have the following validation rule on one of the models, validates :reciept_num, :presence
I have the following regular expression in a validation rule: ^[a-zA-Z0-9',!;?~>+&\\-@#%*.\s]{1,1000}$ However, I can
I have the following validation summary control in the markup: <asp:ValidationSummary ID=vsValErrs CssClass=errors HeaderText=<div><%#
I have the following script validation.php <?php if(!isset($_SESSION['userId'])){ session_destroy(); header('Location: home.php'); exit; } ?>
I have the following code validation php script: if(empty($_POST['captcha_code'])) { $error = 1; $code[3]
I have been following the validation for Entry boxes from here . The code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.