You are viewing limited content. For full access, please sign in.

Question

Question

Set date range in Forms

asked on February 26, 2014

Can we require a DOB date field to be at least 14 years old?

0 0

Answer

APPROVED ANSWER
replied on June 2, 2014 Show version history

If you need to compare the entered date with today's date, you're correct that the date range option will not help. We'll look in to improving date fields and offering more options like this in the future; for now, you can use some straightforward JavaScript to accomplish what you're looking for.

 

To use the following code, add the ageLimit class to your date field. See the Adding classes to fields section of this page for more details.

$(document).ready(function () {
    var d = new Date();
    $('.ageLimit input').change(function () {
        if (d.getFullYear() - ($('.ageLimit input').val().slice(-4)) <= 14) {
            if ($('.ageWarning').length == 0) {
                $('<p class="ageWarning">You must be at least 14 years old to apply.</p>').insertAfter('.ageLimit');
                $('.Submit').attr('disabled', true);
            }
        }
        else {
            $('p.ageWarning').remove();
            $('.Submit').removeAttr('disabled');
        }
    });
});

This code displays a warning and disables the submit button if the entered date is within 14 years of the current year.

3 0

Replies

replied on June 2, 2014

Sure, add the CSS class I mentioned earlier to the birthday field, then use the following code:

 

$(document).ready(function () {
    var d = new Date();
    $('.ageLimit input').change(function () {
        if (d.getFullYear() - ($('.ageLimit input').val().slice(-4)) <= 17) {
            if ($('.ageWarning').length == 0) {
                $('<p class="ageWarning">You must be at least 18 years old to apply.</p>').insertAfter('.ageLimit');
                $('.Submit').attr('disabled', true);
            }
        }
        else {
            $('p.ageWarning').remove();
            $('.Submit').removeAttr('disabled');
        }
    });
});

Feel free to edit the part that says "You must be at least 18 years old to apply." to any warning message you like.

2 0
replied on June 2, 2014

I have the same issue. The date range only allows you to state it cannot be in the future. Is there a way around this? We have several new hires sting they were born this year and we have to go and correct the PDF and resubmit the form. 

0 0
replied on June 2, 2014

Can you assist with the script for the attached screen shot. i am looking for applicants to be 18 years old. the date we would use for that is Birthdate.

Birthdate.PNG
Birthdate.PNG (19.26 KB)
0 0
replied on February 26, 2014

I assume that this question is related to Laserfiche Forms.  If that's incorrect, feel free to clarify below.

 

In Laserfiche Forms, you can configure a date field to only allow a certain range of years.  Within the options of the date field, you'll see "Year range" where you can set the values.  Keep in mind this doesn't read the current date and require a certain age, but you can of course set the range to prevent anyone born after a certain year from submitting the form.  

 

If this answers your question, please mark this response as user approved!  If it doesn't answer your question, feel free to add to the discussion and I'd be happy to offer more help.

0 2
You are not allowed to follow up in this post.

Sign in to reply to this post.