Prevent People Entering a Birthdate in the Future

At present, it is possible for a constituent to enter a birthdate in the future. This is a bit absurd since you generally cannot predict a birthdate. Birthdate should be restricted to today and prior.

  • Guest
  • Oct 23 2020
Area of the Product TeamRaiser
Org/Company Name JDRF
  • Attach files
  • Brian Mucha commented
    October 23, 2020 21:16

    Put this script in the HTML Area on the Registration Information page in your Teamraiser.

    This removes future years from the select, and simulates the default validation on the birthdate fields on date change or submit.

    <script>
    jQuery(document).ready(function ($) {

    if ( $("#cons_birth_date_YEAR").length ) {

    var thisYear = new Date().getFullYear();
    $("#cons_birth_date_YEAR option").each(function() {
    if ( $(this).val() > thisYear ) {
    $(this).remove();
    }
    });

    $("#cons_birth_date_YEAR, #cons_birth_date_MONTH, #cons_birth_date_DAY").change( function() { validateBirthday() });
    $("#F2fRegContact").submit( function(event) { if (validateBirthday()==false) event.preventDefault(); });

    }

    function validateBirthday() {
    if( $("#cons_birth_date_YEAR").val() && $("#cons_birth_date_MONTH").val() && $("#cons_birth_date_DAY").val() ) {
    var thisDate = new Date().getTime();
    var birthDate = new Date( $("#cons_birth_date_YEAR").val(), $("#cons_birth_date_MONTH").val(), $("#cons_birth_date_DAY").val() ).getTime();
    if ( birthDate >= thisDate ) {
    if ( $("#cons_info_dob.form-error").length == 0 ) {
    $("#cons_info_dob")
    .addClass("form-error")
    .prepend("<div class=\"ErrorMessage\">Must be in the past.</div>");
    }
    return false;
    } else {
    $("#cons_info_dob").removeClass("form-error");
    $("#cons_info_dob .ErrorMessage").remove();
    return true;
    }
    }
    }

    });
    </script>