RAW - REGEX
Description
The REGEX validator checks the content of a data point against a specified regular expression (regex). If the data point's value does not match the regex expression, then a violation is thrown. This validator is versatile and can be used to enforce complex validation rules that cannot be easily expressed through standard data type validators. It accepts all data types except BLOBs.
Supported Data Types
The REGEX validator supports all data types except BLOBs, including:
- String
- Integer
- Decimal
- Double
- Boolean
- Json
Config Location
The configuration for the REGEX validator is defined within the <config>
element of the <rawDPValidator>
within a schema data point. This section is crucial for specifying the regex pattern that the validator will use to validate the data item.
Config Requirements
The <config>
element is required for the REGEX validator. If no configuration is provided, or if the configuration is improperly formatted, a block violation will be thrown. This ensures that the validator has the necessary regex pattern to perform its validation task.
Example Config
Below is an example of a REGEX raw validator configuration. This validator checks if the current item matches the regex pattern ^[0-9]{9}$
, which validates that the item is a string of exactly 9 digits.
1 2 3 4 5 6 7 8 9 |
|
Example Results
Consider a scenario where the REGEX validator is applied to a data item named "ID" with a value of "123456789". Since the value matches the regex pattern ^[0-9]{9}$
, the validator will pass successfully without throwing a violation.
On the other hand, if the value of "ID" were "1234567890" (10 digits instead of 9), the validator would throw a violation because the value does not match the specified regex pattern.
Common Mistakes
- Ensure that the regex pattern within the
<config>
element is correctly formatted and matches the intended validation criteria. Incorrectly formatted regex patterns can lead to unexpected validation outcomes. - Verify that the
entity
attribute of the<rawDPValidator>
element is correctly set to "REGEX" to apply the REGEX validation logic. - Remember that the REGEX validator is powerful but requires careful configuration to avoid unintended validation outcomes.