Validation
You can set a validator to already existing attributes but to save it, a value of this attribute in all products MUST match the validation parameters. If they don't, an error message will be displayed.
Introduction
Validators help protect data integrity by ensuring that only data meeting specific conditions is accepted into the system. For example, when dealing with text type attributes, you can use regular expressions (regex). Imagine regex as a pattern filter that checks if the attribute value looks correct; for instance, it verifies that an email address includes an "@" symbol. This helps maintain accuracy and prevent errors.
Different attribute types require different validation rules. A number might need to be within a certain range, whereas an image might need to fall within specific boundaries. Validators thus help maintain consistency across your data fields.
In Ergonode you can set validation to the following attribute types:
File
Minimum number of files
Maximum number of files
Maximum file size
Allowed extensions
Gallery
Minimum number of images
Maximum number of images
Maximum file size
Allowed extensions
Image
Maximum file size
Allowed extensions
Numeric
Minimum value
Maximum value
Price
Minimum value
Maximum value
Text
Regular expression (regex) with examples
Textarea
List of banned words (1000 characters limit)
Unit
Minimum value
Maximum value
About regex (available in text attribute only)
In the system, you can use some predefined regex patterns, but it's possible to use your own. To use predefined ones click on the "Copy from regex templates".
Regular expressions, or regex, are like super-powered validation tools for text. They use a specific sequence of characters to form a specific pattern. You can think of it as a sophisticated “find,” but with more precision and flexibility. Here's how to use regex for validating:
Basic Validation:
Suppose you want to validate any three-letter words. You'd use the pattern
\b\w{3}\b
. In this pattern,\b
indicates word boundaries, and\w{3}
specifies exactly three word characters.
Digits Validation:
To validate any sequence of digits in text, use the pattern
\d
. Here,\d
stands for any digit, so this will match any sequence of strings with a single digit in it. like 123, 4aa, or 678aaa9. If you wish to validate a string that ends with a digit use\d$
, ex: something1.
Email Addresses Validation:
If you're validated for email addresses, you might use something like
\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b
. This looks for common email structures, checking for alphanumeric characters before and after the "@" symbol.
Dates validation:
To validate the dates in the format DD/MM/YYYY, you could use
\b\d{2}\/\d{2}\/\d{4}\b
. Here,\d{2}
finds exactly two digits,/
is a literal slash, and\d{4}
looks for four digits.
Flexible Validation:
Sometimes, you might want to validate words that start with a certain letter. For example, to find words starting with “a” use
\ba\w*\b
. This looks for word boundaries (\b
), the letter "a," and any number of word characters (\w*
).
Regex provides a way to quickly find patterns and extract relevant information from text without manual searching. They might seem complex at first, but with practice, they become incredibly useful for tasks like data validation and text processing. Dive in and explore the endless possibilities they offer!
Included regex patterns
In Ergonode you will find some common regex patterns already included for your convenience.
Here is the list:
EAN-13
EAN-8
URL address
File Path
Alphanumeric (without space)
Alphanumeric (with space)
Numeric (whole numbers)
Numeric (dot separated)
Numeric (comma separated)
To use them click on Copy from regex templates and select one from the list.
Custom regex validation error message
You can set a custom validation error message for your user.
The message will be displayed on the validation box
in the tooltip on the Product catalog (Product grid)
in the Category attribute (if the attribute is set to be one)
in the Batch action
and on the product card.
Last updated