How do I add validation rules for Benefits contact pages?

Here's how:

  1. Navigate to Me > Benefits > Before You Enroll. You can any other pages that support validation rules.
  2. On the Settings and Actions menu in the global header, click Edit Page in Visual Builder Studio. Ensure that you've appropriate access to the VB Studio configuration to see this option.
  3. Click the Validate Fields Value button.
  4. If you haven’t created validations before, click Validation.
  5. Add a label and click Create.
  6. Click Edit in the Conditions region.
  7. Create the conditions for your validation rule.
  8. Click Done.
  9. Add the summary, severity, and details of the message.
  10. Here's how you use advanced validation rules:
    1. Click the Use Advanced Conditions button.
    2. Click the Code button.
    3. Add the Java Script code.
  11. Save your changes.
  12. Preview and publish your changes.

All the benefits contact pages support these advanced validation rules.

Supported Validation Rules on Benefits Contact Pages

Validation Rules Sample Java Script
Require national identifier for specific relationship type and age.
/* eslint-disable dot-notation */
define([], () => {
  'use strict';
  
  function isOlderThanSixMonths(dob) {
    const currentDate = new Date();
    const birthDate = new Date(dob);   
    // Calculate the difference in months
    const monthDiff = currentDate.getMonth() - birthDate.getMonth() +
                      (12 * (currentDate.getFullYear() - birthDate.getFullYear()));
    // Check if the age is greater than or equal to 6 months
    const isOlderThanSixMonths = monthDiff > 6 || (monthDiff === 6 && currentDate.getDate() >= birthDate.getDate());
 
    return isOlderThanSixMonths;
}
  
  /**
   *
   * @param {object} context
   * @return {boolean}
   */
  function runCondition(context) {
    const { $objectContext, $fields, $modules, $user, $value } = context;
  
    let dob =  $fields['contactRelationships']['dateOfBirth'].$value();
    let nidCountry = $fields['personNationalIdentifiers']['LegislationCode'].$value();
  
    if ( dob && isOlderThanSixMonths(dob) && (nidCountry == null || nidCountry == "")) {
      return true;
    }
  
    return false;
  }
  
  return { runCondition };
});
Require national identifier for specific relationship type.
/* eslint-disable dot-notation */
define([], () => {
  'use strict';
   
  /**
   *
   * @param {object} context
   * @return {boolean}
   */
  function runCondition(context) {
    const { $objectContext, $fields, $modules, $user, $value } = context;
 
    if (($fields['contactRelationships']['ContactType'].$value() == 'S' || $fields['contactRelationships']['ContactType'].$value() == 'DP' || $fields['contactRelationships']['ContactType'].$value() == 'P') && ($fields['personNationalIdentifiers']['LegislationCode'].$value() == '' || $fields['personNationalIdentifiers']['LegislationCode'].$value() == null)) {
      return true;
    }
 
    return false;
  }
 
  return { runCondition };
});

Require date of birth for specific relationship types.
/* eslint-disable dot-notation */
define([], () => {
  'use strict';
  
  /**
   *
   * @param {object} context
   * @return {boolean}
   */
  function runCondition(context) {
    const { $objectContext, $fields, $modules, $user, $value } = context;
 
    if (($fields['contactRelationships']['ContactType'].$value() == 'S' || $fields['contactRelationships']['ContactType'].$value() == 'DP' || $fields['contactRelationships']['ContactType'].$value() == 'C') && ($fields['contactRelationships']['dateOfBirth'].$value() == '' || $fields['contactRelationships']['dateOfBirth'].$value() == null)) {
      return true;
    }
 
    return false;
  }
 
  return { runCondition };
});
Require home address for specific relationship types.
/* eslint-disable dot-notation */
define([], () => {
  'use strict';
 
  /**
   *
   * @param {object} context
   * @return {boolean}
   */
  function runCondition(context) {
    const { $objectContext, $fields, $modules, $user, $value } = context;
 
    if (($fields['contactRelationships']['ContactType'].$value() == 'S' || $fields['contactRelationships']['ContactType'].$value() == 'DP' || $fields['contactRelationships']['ContactType'].$value() == 'C') && ($fields['personAddress']['AddressLine1'].$value() == '' || $fields['personAddress']['AddressLine1'].$value() == null)) {
      return true;
    }
 
    return false;
  }
 
  return { runCondition };
});
Require phone number for contacts marked as emergency contact.
/* eslint-disable dot-notation */
define([], () => {
  'use strict';
  
  /**
   *
   * @param {object} context
   * @return {boolean}
   */
  function runCondition(context) {
    const { $objectContext, $fields, $modules, $user, $value } = context;
 
    if (($fields['contactRelationships']['EmergencyContactFlag'].$value() == true) && ($fields['personPhones']['LegislationCode'].$value() == '' || $fields['personPhones']['LegislationCode'].$value() == null)) {
      return true;
    }
 
    return false;
  }
 
  return { runCondition };
});
Require gender and date of birth for a specific legislation and only for benefit eligible contacts.
/* eslint-disable dot-notation */
define([], () => {
  'use strict';
 
  /**
   *
   * @param {object} context
   * @return {boolean}
   */
  function runCondition(context) {
    const { $objectContext, $fields, $modules, $user, $value } = context;
     
    if(($objectContext.LegislationCode.includes('US'))){
    if (($fields['contactRelationships']['dateOfBirth'].$value() === null || $fields['contactRelationships']['gender'].$value() === null) && $fields['contactRelationships']['ContactTypeMeaning'].$value() === 'Spouse') {
      return true;
    }
  }
  return false;
  }
 
  return { runCondition };
});