Adding Validation for Date of Birth Field

This validation ensures that a valid value is specified for the Date of Birth field.

Procedure

  1. Click the Date of Birth field.
  2. Click the Validations tab on the control’s Properties view.
  3. Click the Add New Validation button.

    The Define Validation dialog opens.

  4. In the Name field type the following:
    birth_date_validation
    Tip: Using names for validation scripts that describe their function makes it easier for another designer to understand the form later if modifications must be made.
  5. Click the radio button On Value Change.
  6. Type the following JavaScript code in the Script text area:
    var date = this.getValue();
    var now = new Date();
    //Validate birth date some time before today's date and
    //within 120 years
    if(date == null || 
      (date < now && now.getFullYear() - date.getFullYear() < 120)){
     true;
    } else{
     false;
     }
  7. Type the following text in the Message area:
       Enter a valid birth date which is a past date and in the range of last 120 years.
  8. Click Finish.