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 8854893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:59:24+00:00 2026-06-14T13:59:24+00:00

I have a registration form with a required date of birth field. <tr> <td><span

  • 0

I have a registration form with a required date of birth field.

    <tr>
      <td><span class="required">*</span> <?php echo $entry_dob; ?></td>
      <td><input type="text" id="dob" name="dob" value="<?php echo $dob; ?>"   /><p id="age"></p>
        <?php if ($error_dob) { ?>
        <span class="error"><?php echo $error_dob; ?></span>
        <?php } ?>

So in my php controller file [ I am using a software coded in MVC], I Have the following the following function to make the field required:

 if ((strlen(utf8_decode($this->request->post['dob'])) < 3) || (strlen(utf8_decode($this->request->post['dob'])) > 32)) {
        $this->error['dob'] = $this->language->get('error_dob');
    }

I also need to validate if the user is a least 19 years old. If he/she is not, an error will be displayed, I am using the following function in the same php controller file to achieve this:

$allowed_age = 19;
$bdate = strtotime($_REQUEST['dob']);
$age = (time()-$bdate)/31536000;
if($age < $allowed_age) {
 $this->error['dob'] = $this->language->get('error_dob');
}

And I have tested it and it seems to be working properly. However, I was wondering how can I validate the two things at once. I mean, validate if the user has input the dob, and if the age is older than 19.

I am not an expert, so if you know a better way to achieve this, please share it.

Best Regards,

Codekmarv

  • 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-14T13:59:25+00:00Added an answer on June 14, 2026 at 1:59 pm

    use this to get the age

    $age = floor( (strtotime(date('Y-m-d')) - strtotime($this->request->post['dob'])) / 31556926);
    

    and after that take $age value and just check it in if condition

    if (((strlen(utf8_decode($this->request->post['dob'])) < 3) || (strlen(utf8_decode($this->request->post['dob'])) > 32)) 
    && $age < 19) {
        $this->error['dob'] = $this->language->get('error_dob');
    }
    

    It will check for user has inputed a value and age is greater than 19.

    You have to use && operator to check multiple conditions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a registration form that has some required field. i want to check
I have a registration form and used fieldset to order the input fields in
I am using jquery validation plugin to validate a registration form. Each text input
i have a members registration form that displays perfectly until i add the php.
I have added 2 custom attributes to the registration form to collect input from
I am trying to create a simple registration form. I have the following: include('User.datatype.php');
Hi I have the following code: <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <title>Registration Form</title>
I need to validate a text field in my registration form for which I
I have default FOSUserBundle registration form. I want to add jabber field into registration
I have a working PHP registration form that goes through $_POST[] requests to check

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.