Add validations and related logic

📘

Most of the content on this page deals with a legacy feature of the ​Akamai​ Identity Cloud (in this case, the JavaScript SDK). If you are currently an Identity Cloud customer and are using the JavaScript SDK, that SDK is still supported. However, if you’re new to the Identity Cloud the JavaScript SDK is no longer available. Instead, you should use Hosted Login for your login and registration needs.


Make a field required ... or optional

To make a field required, add or update a field to include the rule “required” with value “true”, as in the example below. If you wish to make an already-required field optional, you can either remove the validation or set the value to “false”. If creating a new field, remember to add the new field to the relevant forms in order to utilize it.

{
  "label": "My Required Field",
  "name": "myRequiredField",
  "schemaAttribute": "optIn.status",
  "type": "text",
  "validation": [
    {
      "message": "This field is required",
      "rule": "required",
      "value": true
    }
  ]

📘

Prefer to use Console and Registration builder to work with fields? Then see the article Manage fields in Registration Builder.


.

Add Captcha to a form

To add Captcha to a form, you need to make changes in your Flow, your form markup, and your JavaScript settings.

  1. In your Flow, make a GET call to the /config/{app}/flows/{flow}/forms/{form} operation to verify you will be modifying the correct form. Once verified, add the “captcha” feature to your form and make a PUT request to the same operation:
{
     "features": [
         "name":
         "captcha"
                 ],
     "fields":   [
        ...      ]
    }
  1. In your form markup, add the { captcha } JTL tag to your form:
<div style="display:none;" id="traditionalRegistration">
     {* #registrationForm *}
         <!-- ... -->
         {* captcha *}
         <!-- ... -->
     {* /registrationForm *}
    </div>
  1. In your JavaScript settings, add the recaptchaVersion = 2 setting to specify the version of Captcha to render:
janrain.settings.capture.recaptchaVersion = 2;
  1. Enable Invisible reCaptcha (optional). You can also enable invisible reCaptcha by adding an additional JavaScript setting:
janrain.settings.capture.recaptchaInvisible = true;

Invisible reCaptcha only presents a challenge to the user if that user is suspected of being a bot. If not, no challenge is presented, and the user continues on as if reCaptcha wasn’t even installed.  For better bot management, please also see your ​Akamai​ representative about our line of Bot Manager products.


Enforce age restrictions and gating

The birthdate field in the standard flow already supports age-gating and defaults to a minimum age of 16; simply include it on your forms where needed. What follows are instructions on how to modify this field or add additional age-gated fields.

To enforce age restrictions, you can add or update a dateselect field such that it has a validation object with the minYears (and also required) rules. Then, you can add this field to the traditionalRegistration and socialRegistration screens (the registrationForm and socialRegistrationForm forms in your Flow, respectively). Below is an example birthday field that only allows users 18 or older to register. Remember to add the new field to the relevant forms in order to utilize it.

{
  "label": "Birthday",
  "name": "birthday",
  "schemaAttribute": "birthday",
  "type": "dateselect",
  "validation": [
    {
      "rule": "required",
      "value": "true",
      "message": "Birthdate is required"
    },
    {
      "rule": "minYears",
      "value": 18,
      "message": "You must be at least 18 years old to register"
    }
  ]
}

📘

If you wish to implement site-specific (API client specific) age-gating, this is supported; however, age-gating is not configurable via the Configuration API. Please contact your ​Akamai​ representative for more information.