Home Tags, attributes and custom fields Validation with Regular Expressions (REGEX) in Custom Fields for 'Text' Type

Validation with Regular Expressions (REGEX) in Custom Fields for 'Text' Type

Last updated on Sep 02, 2026

What is REGEX?

REGEX, or regular expressions, is a tool used to search for patterns in texts. It is widely used in programming and systems to validate data input, ensuring that it is in the correct format.

How does REGEX validation work?

REGEX validation uses specific patterns to verify if the entered text matches the expected pattern. If the text does not match the pattern, it is considered invalid. This is an effective way to prevent data errors or malicious entries in a system.

Examples of using REGEX validation:

  1. Validate emails: Ensures the user enters a valid email address.

    • REGEX Pattern: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$

    • Description: The email should start with alphanumeric characters (including ._%+-), followed by @, then more alphanumeric characters, a dot, and finally, 2 or more alphabetic characters.

  2. Validate phone numbers: Confirms if the phone number is in the correct format.

    • REGEX Pattern: ^(\d{2})\s\d{4,5}-\d{4}$

    • Description: The phone should be in parentheses, containing two digits, followed by a space, 4 or 5 digits, a hyphen, and 4 more digits. Example: (11) 9999-9999 or (11) 99999-9999.

  3. Validate CPF: Checks if the CPF is in the correct format with or without dots and hyphen.

    • REGEX Pattern: \d{3}.\d{3}.\d{3}-\d{2}$|(\d{11})$

    • Description: The CPF should have 11 digits, either formatted with dots and hyphen or as just digits.

  4. Validate dates: Ensures that the date input is in the day, month, and year format.

    • REGEX Pattern: ^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/\d{4}$

    • Description: The date should be in the format DD/MM/YYYY, where DD is between 01 and 31, MM is between 01 and 12, and YYYY is a valid year with 4 digits.

  5. Validate passwords: Ensures that the password meets specific security criteria.

    • REGEX Pattern: ^(?=.[a-z])(?=.[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$

    • Description: The password must be at least 8 characters long, including at least one uppercase letter, one lowercase letter, and one number.

How to insert a REGEX pattern?

In most systems supporting REGEX, you will find a field where you can enter the desired pattern. Remember to test the pattern to ensure it works as expected before applying it to the system.

How can I learn more about REGEX?

There are many online resources, including tutorials, courses, and interactive tools, that can help you learn and practice regular expressions. Sites like Regex101 allow you to test your regular expressions and see detailed explanations of how they work.

Bonus: ChatGPT is great for generating this. Ask it for a REGEX validator in the format you want, and it has a high chance of generating a useful function since it’s quite technical.

Hope this article helps clarify how you can use regular expressions to improve data validation in your custom fields!