Elements of the type <input date...
accept the attribute max
, however you will need to somehow calculate the minimum date of birth based on the current date to assign this value, example:
Based on today’s date (23/03/2017) the minimum date should be (23/03/1999), so you should put this value in the min attribute of the element in the format AAAA-MM-DD
.
<form>
<label for="txtData_Nasc">Data de nascimento:</label>
<input type="date" class="form-control" id="txtData_Nasc" name="txtData_Nasc" max="1999-03-23" required>
<input type="submit"/>
</form>
To calculate the date automatically as php in this case:
<label for="txtData_Nasc">Data de nascimento:</label>
<input type="date" class="form-control" id="txtData_Nasc" name="txtData_Nasc" max="<?php echo date('Y-m-d', strtotime('-18 year')); ?>" required>
Example date calculation in Ideone
it would be more convenient for you to leave the "free" field and check your code by comparing the dates, if the user is under age you display a message.
– RFL
You can do this without having to update the page?
– Everton Figueiredo
with javascript yes.
– RFL
How would I do? I’m beginner and I’m starting in this area now.
– Everton Figueiredo
Take a look here @Evertonfigueiredo
– Marconi