Validation

Validating fields (text or other) is crucial for ensuring that data entered by users meets specific criteria or formats and for maintaining data integrity and security.

In Jigx Builder you can use regular expressions (regex) for text validation. They allow for pattern matching and can enforce complex rules for text fields such as email addresses, phone numbers, usernames, passwords, and more. When applied to text validation, regex can be used to check if the input text matches the desired format. If it is not valid, an invalid message is displayed.

In Jigx you combine a JSONata expression with a Regex expressions to create a validation pattern and provide a message if the pattern does not match.

Creating the validation expression:

  1. JSONata expression - [email protected]

  2. Regex expression - /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/

  3. Validation message - not an email

Combine the three above to validate an email address in the text-field component.

YAML
- type: component.text-field
          instanceId: email
          options:
            label: Email
            errorText: =$contains(@ctx.components.email.state.value, /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/) ? '' :'not an email'

Regex and JSONata Expression examples

Here are some common validation expressions to create and use for text field validation.

Validation
Expected result

+271234556789

Typically 13-16 digits, with spaces or dashes optional, and includes checks for Visa, MasterCard, American Express, and Discover. 1111-1111-1111-1111 or 1111 1111 1111 1111

5-digit codes, e.g. 10036

111,25

12:15 AM or 08:45 PM

example.com or https://example.com

978-1-4302-1998-9

See Also

Last updated

Was this helpful?