Here it is explained how to allow only people of legal age to submit the form.
In this example, it is assumed that "%d/%m/%Y" date format is used.
To make it able only for people of legal age to submit a form follow these steps:
1) Create a "Calendar" element with format "%d/%m/%Y".
2) Go to Properties of that calendar element, scroll down and in the "Validation" section check the "Required" checkbox, set Type to "Custom".
In the code area that appears below paste the following code:
function ff_CalendarElementName_validation(element, message) { // Checking if the entered date is in right format var pattern = /[0-3][0-9]\/(0|1)[0-9]\/(19|20)[0-9]{2}/; if(pattern.test(element.value)) { var date_array = element.value.split('/'); var day = date_array[0]; // Attention! Javascript consider months in the range 0 - 11 var month = date_array[1] - 1; var year = date_array[2]; // This instruction will create a date object birthDate = new Date(year,month,day); if(year != birthDate.getFullYear()) { return message == '' ? "Date isn't entered in the right format.\n" : message; } if(month != birthDate.getMonth()) { return message == '' ? "Date isn't entered in the right format.\n" : message; } if(day != birthDate.getDate()) { return message == '' ? "Date isn't entered in the right format.\n" : message; } } else { return message == '' ? "Date isn't entered in the right format.\n" : message; } var now = new Date(); var dobYear = birthDate.getFullYear(); var dobMonth = birthDate.getMonth(); var dobDay = birthDate.getDate() var age = now.getFullYear() - dobYear; var ageMonth = now.getMonth() - dobMonth; var ageDay = now.getDate() - dobDay; if (ageMonth < 0 || (ageMonth == 0 && ageDay < 0)){ age = parseInt(age) - 1; } if (age < 18) { if (message=='') message = "Only persons of legal age can submit this form.\n" ff_validationFocus(element.name); return message; } // if else if (age >= 18){ return ''; } } // ff_CalendarElementName_validation
NOTE: In the code above you have to replace "CalendarElementName" with the name of that calendar element in your form.
This way, an error message will appear after clicking on the submit button if the age of the person isn't above 18.
Therefore, only users of legal age will be able to submit the form.