Skip to main content

Validating data against a pattern

3 Tasks

10 mins

Visible to: All users
Intermediate Pega Platform 8.7 Data Integration English
Verify the version tags to ensure you are consuming the intended content or, complete the latest version.

Scenario

TGB has decided to open a branch office in India. Candidates from India must provide an Aadhaar ID for identification purposes. Ensure that candidates located in India enter an Aadhaar ID that satisfies the following requirements:

  • The ID does not contain alphabetic or special characters.
  • The ID consists of three groups of four numbers, with a space separating each group of four.
  • The ID does not start with either a "0" or "1".

Configure the Candidate information layout on the Collect personal details step to display a field for the Aadhaar ID. Configure the form so that the field is displayed and is required only if the user provides the three-character country code for India (IND).

Note: For more information about the Aadhaar ID program, see https://en.wikipedia.org/wiki/Aadhaar.

The following table provides the credentials you need to complete the challenge.

Role User name Password
Senior System Architect SSA@TGB pega123!

You must initiate your own Pega instance to complete this Challenge.

Initialization may take up to 5 minutes so please be patient.

Challenge Walkthrough

Detailed Tasks

1 Create an Edit validate rule to test the Aadhaar ID pattern

  1. In Dev Studio, on the Create menu, click Data Model > Edit Validate to display the Create Edit Validate form.
  2. On the Create Property form, in the Label field, enter Validate Aadhaar ID.
  3. Click Create and open to create the edit validate rule.
  4. On the Validate Aadhaar ID edit validate form, in the Java Source field, enter the following Java code.

    // Regex to check valid Aadhaar number
    String regex= "^[2-9]{1}[0-9]{3}\\s[0-9]{4}\\s[0-9]{4}$"; 

    // Compile the ReGex
    java.util.regex.Pattern p = java.util.regex.Pattern.compile(regex); 

    // If the string is empty, return false
    if (theValue == null || theValue.trim().equals("")) return false;

    // Pattern class contains matcher() method to match the given string and the regular expression
    java.util.regex.Matcher m = p.matcher(theValue); 

    // Return if the string matched the ReGex
    return m.matches();

  5. Click Save to complete the configuration of the Edit validate rule.
    Java code for validating the format of an entered Aadhaar ID.

2 Create the Aadhaar ID property

  1. On the Create menu, click Data Model > Property to display the Create Property form.
  2. On the Create Property form, in the Label field, enter Aadhaar ID.
  3. In the Class field, enter TGB-HRApps-Data-Candidate.
    Note: By default, only classes that correspond to data types listed in the Data Explorer are presented in the list of available classes. You can expose the data type in the Data Explorer to add the TGB-HRApps-Data-Candidate class to the list of choices.
  4. Click Create and open to create the property rule.
  5. On the Aadhaar ID property form, click the Advanced tab.
  6. On the Advanced tab, in the Max length field, enter 14 to prevent the user from entering a value longer than 14 characters.
  7. In the Expected length field, enter 14.
  8. In the Use validate field, enter or select ValidateAadhaarID to apply the Validate Aadhaar ID edit validate rule when the user provides a value for the property.
  9. Click Save to complete the configuration of the Aadhaar ID property.
    The Advanced tab of the Aadhaar ID property.

3 Add the Aadhaar ID field to the Collect personal information step

  1. In the App Explorer, select Candidate > User Interface > Section > CollectPersonalDetails_0 to open the Collect personal details section.
  2. Click the header of the CollectPersonalDetails_0_Candidate embedded section layout.
  3. In the layout header, click the Open Rule icon to open the embedded CollectPersonalDetails_0_Candidate section on a new tab.
    The CollectPersonalDetails_0_Candidate embedded section layout, with the Open Rule icon highlighted in the layout header.
    Note: When you open the embedded section, your browser presents a warning stating that changes to the embedded section are not reflected in the CollectPersonalDetails_0 section until the section is refreshed. Click OK to dismiss the dialog.
  4. Save a copy of the CollectPersonalDetails_0_Candidate section in an unlocked ruleset version.
  5. In the Data capture list, select Text input.
  6. Drag the cursor to the Candidate information layout, and place the text input control to the right of the Home Phone field.
  7. Double-click the text input field to open the Cell Properties dialog box.
  8. In the Cell Properties dialog box, in the Property field, enter or select .AadhaarID.
  9. In the Visibility list, select Condition (expression). The Cell Properties dialog box updates to display the Condition for visibility field under the Visibility field.
  10. In the Condition for visibility field, enter .pyCountryCode='IND'.
  11. In the Required list, select Condition (expression). The Cell Properties dialog box updates to display the Condition for required under below the Visibility field.
  12. In the Condition for required field, enter .pyCountryCode='IND'.
    Aadhaar ID field cell properties panel configured to support visibility and entry requirements.
  13. Click Submit to close the Cell Properties dialog box.
  14. Click Save to complete the configuration of the section rule.
  15. Click Check in to check in the rule and prevent further editing of the section.

Confirm your work

  1. On the Create menu, click New > Candidate to create a Candidate case.
  2. On the Collect personal information form, enter information in the following required fields.
    Field Value
    Position Director
    First Name Ramesh
    Last Name Singh
    Email [email protected]
    Taxpayer ID 000-00-0000
  3. In the 3-letter country code field, enter IND.
  4. Click out of the 3-letter country code to update the form and display the Aadhaar ID field.
  5. In the Aadhaar ID field, enter the values in the following table, and then click out of the field to test the validation logic for the field. Each value in the table causes the validation to fail.
    Value Condition causing failure
    1234 5678 90 Insufficient number of digits
    1234 5678 9012 Entered value begins with "1"
    223456789012 No separating characters
    2234 5678 90AB Alphabetic characters
    Note: If clicking out of the Aadhaar ID field does not trigger the validation, click Submit.
    The Collect personal information form, displaying a validation failure for the Aadhaar ID field.
  6. In the Aadhaar ID field, enter 2234 5678 9012.
  7. Click out of the field and confirm that no error is displayed.
    The Collect personal information form, demonstrating successful validation of the Aadhaar ID field.

This Challenge is to practice what you learned in the following Module:


Available in the following mission:

If you are having problems with your training, please review the Pega Academy Support FAQs.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Academy has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice