title: PHP Validate required field + age validation in one function
body: <p>I have a registration form with a required date of birth field.</p>
  
  <pre><code>    &lt;tr&gt;
        &lt;td&gt;&lt;span class="required"&gt;*&lt;/span&gt; &lt;?php echo $entry_dob; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input type="text" id="dob" name="dob" value="&lt;?php echo $dob; ?&gt;"   /&gt;&lt;p id="age"&gt;&lt;/p&gt;
          &lt;?php if ($error_dob) { ?&gt;
          &lt;span class="error"&gt;&lt;?php echo $error_dob; ?&gt;&lt;/span&gt;
          &lt;?php } ?&gt;
  </code></pre>
  
  <p>
          </p>
  
  <p>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:</p>
  
  <pre><code> if ((strlen(utf8_decode($this-&gt;request-&gt;post['dob'])) &lt; 3) || (strlen(utf8_decode($this-&gt;request-&gt;post['dob'])) &gt; 32)) {
          $this-&gt;error['dob'] = $this-&gt;language-&gt;get('error_dob');
      }
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>$allowed_age = 19;
  $bdate = strtotime($_REQUEST['dob']);
  $age = (time()-$bdate)/31536000;
  if($age &lt; $allowed_age) {
   $this-&gt;error['dob'] = $this-&gt;language-&gt;get('error_dob');
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>I am not an expert, so if you know a better way to achieve this, please share it.</p>
  
  <p>Best Regards,</p>
  
  <p>Codekmarv</p>