-5

I am using a date picker from twitter bootstrap and I want to add some validation that your sign up will not suppose to be registered once your date is below 18 years of age, how am I supposed to do that? here is my sample html code for the birthdate:

<label>Date of Birth*</label>
<input type="date" name="birth_date" tabindex="7" style="height: 30px;" required>
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
user3819129
  • 49
  • 1
  • 1
  • 5
  • Set the `min` attribute based on today's date - 18 years (html5). But, anyway, you have to check it on server-side and/or with js. – Cheery Oct 28 '14 at 17:50
  • Best way is to proceed to javascript limitation for user experience and php limitation for security. – gr3g Oct 28 '14 at 17:51
  • I'm sorry but I dont know how to do it in javascript, I'm just a beginner in developing.. so sorry, will someone show me how to do it? – user3819129 Oct 28 '14 at 17:53
  • 1
    You either need to (a) brush up on your basic Javascript skills and work your way up to something a bit more complex such as this, or (b) hire a professional to do it for you. – esqew Oct 28 '14 at 17:54

2 Answers2

0

You need to validate the user input either using javascript or the scripting language you're going to use.

An example in PHP would be:

<?php

if(isset($_POST['birth_date']))
{
   if($_POST['birth_date'] < 1996)
   {
      echo 'You can not register';
   }

}
Matthew
  • 93
  • 2
  • 6
0

If you look down the demo page a bit, you'll see a "Restricting Datepicker" section. Use the dropdown to specify the "Year dropdown shows last 20 years" demo , and hit view source:

$("#restricting").datepicker({ 
    yearRange: "-20:+0", // this is the option you're looking for
    showOn: "both", 
    buttonImage: "templates/images/calendar.gif", 
    buttonImageOnly: true 
});

You'll want to do the same (obviously changing -20 to -100 or something).

Or you can use

$('#dp1').datepicker({
    format: 'mm-dd-yyyy',
    startDate: '-15d',
    endDate: '+0d' // there's no convenient "right now" notation yet
});
Shailendra Sharma
  • 6,976
  • 2
  • 28
  • 48