Validating Dynamic Fields with Regular Expressions
Text-type dynamic fields in ReflexBlue allow you to use Regular Expressions (regex) to validate user-input. By carefully crafting your regex, you can ensure that the data entered into these fields meets your specific requirements.
Setting up regex validation
When adding or editing a text-type dynamic field, you’ll find two key fields related to Regular Expressions under the field section in the Dynamic Fields detail screen:
-
RegEx validation: This field is where you specify the Regular Expression that will be used to validate the input for this dynamic field. For information about creating a regex pattern, see Regular Expressions Reference.
-
RegEx testfield: This field allows you to test the Regular Expression specified in the RegEx validation field to ensure it works as expected.
Testing your regex validation
Use the RegEx testfield to input different test cases and see if the Regular Expression in the RegEx validation field correctly validates the input. This is a great way to ensure that your validation rules work as expected before finalizing the dynamic field.
Example Regular Expressions for text validation
The examples provided below can serve as a starting point for creating your own validation rules, tailored to your specific needs. For more information about creating a regex pattern, see Regular Expressions Reference.
-
Validating Email addresses
- Regex:
^[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$ - Explanation: This regex ensures that the input is a valid email address. It checks for a sequence of word characters, dots, percent signs, plus signs, or hyphens before the
@symbol, followed by a domain name and a valid top-level domain (e.g.,.com,.org).
- Regex:
-
Validating a phone number (e.g., Dutch format)
- Regex:
^\+31\s\d{2}\s\d{8}$ - Explanation: This regex checks for a Dutch phone number format starting with
+31, followed by a space, two digits for the area code, another space, and then eight digits for the phone number.
- Regex:
-
Validating postal codes (e.g., Dutch format)
- Regex:
^\d{4}\s?[A-Z]{2}$ - Explanation: This regex validates Dutch postal codes, which consist of four digits followed optionally by a space, and then two uppercase letters.
- Regex:
-
Validating a URL
- Regex:
^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$ - Explanation: Explanation: This regex validates a URL, allowing for optional http:// or https://, followed by a domain name, top-level domain, and optional path.
- Regex:
-
Validating a product code
- Regex:
^[A-Z0-9]{5,10}$ - Explanation: This regex ensures the product code is between 5 and 10 characters long, consisting of uppercase letters and digits.
- Regex: