Example: Use a constraint with a regular expression on a field to add "smart-code" validation

Employees can add telephone numbers to their employee profile. The Phone Number field is an alpha field with no edits against entered values. This means a user can enter the phone number in any number of formats and the application will store the value. For example, "(XXX)XXX-XXXX" or "XXX.XXX.XXXX" or "XXXXXXXXXX". Data in multiple formats could cause problems if you need to work with those numbers in the future, such as extract them from the database.

You can create a customization to add a validation to the field that ensures enter Phone Numbers using a standard format: XXX-XXX-XXXX.

  1. In the Rich Client, access the form where add their telephone numbers to their profile.
  2. From the form, add a configuration. On the form, press Ctrl + Shift + left-mouse click and click the Configure link.
  3. On the Create New Configuration prompt, click Create.

    The form configuration opens in Configuration Console.

  4. Click the Edit LPL pencil icon.
  5. In the Phone Number field, add a constraint for the field with a regular expression. The constraint enforces that the phone number must be digits with sections separated by a hyphen.
    ContactDetail.Telephone.SubscriberNumber
        propagated from field.Telephone.form.Telephone
        label is "PhoneNumber"
        constraint (ContactDetail.Telephone.SubscriberNumber matches "^[1-9]\d{2}-\d{3}-\d{4}$")
              
  6. Add an error message that provides the correct format for users who enter text that doesn't match the constraint.
    ContactDetail.Telephone.SubscriberNumber
        propagated from field.Telephone.form.Telephone
        label is "PhoneNumber"
        constraint (ContactDetail.Telephone.SubscriberNumber matches "^[1-9]\d{2}-\d{3}-\d{4}$")
            "FormatNeededIsXXX-XXX-XXXX"
              
  7. Save the configuration. Click the Save icon in the LPL editor toolbar.
  8. Close the Configuration Console and test your changes.

    The form you launched the Configuration Console from will still be open in the background. Close the form and relaunch the form. Click Add Phone.

    1. On the Add A Telephone number screen, complete the required fields.
    2. In the Phone Number field, specify a phone number that does not conform to the new format: (555)555-5555.
    3. Click OK.

      The application displays an error message: "Invalid Data: User Configured Constraint format needed is XXX-XXX-XXXX"

    4. Dismiss the error message. Click OK.
    5. In Phone Number, specify a phone number that conforms with the format: 555-555-5555.
    6. Click OK. The record is saved.