Regular expressions (regex) are a sequence of characters that define a pattern. They are used to find and match similar patterns in a piece of text. In other words, regex is a set of strings that holds a particular pattern. It is commonly used to authenticate values entered by the users during submission of any form. It helps:
Some common instances where regex can be useful in validating user's input:
In addition to creating regex pattern while defining a criteria in layout/validation rules, there's also an option to select preferred regex patterns from the regex gallery. With regex gallery, you can use the predefined regex patterns at any time, eliminating the need to create the pattern every time.
Following are the Regex patterns that are available in the gallery:
Regex pattern | Description |
Alphanumeric Characters (letters [a-z] and digits [0-9]) | This pattern ensures that the input contains a combination of lowercase letters and digits. Example: `abc123` (contains letters and digits) |
Alphanumeric Characters with Space | This pattern allows letters, digits, and spaces. Example: `hello world123` (contains letters, digits, and a space) |
Alphanumeric Characters with "-" or "_" | This pattern permits letters, digits, hyphens "-", and underscores "_". Example: `user-name_123` (contains letters, digits, hyphen, and underscore) |
Alphabets Only | This pattern accepts only lowercase or uppercase letters. Example: `alphabetsonly` (contains letters only) |
Alphabets Only with Space | This pattern allows letters and spaces. Example: `words only` (contains letters and a space) |
Numbers Only | This pattern validates that the input consists solely of digits. Example: `123456` (contains digits only) |
URL | This pattern verifies a standard URL format. |
Email ID | This pattern ensures the input follows a standard email format. |
Mobile Number (10 digits, optional +91 or 0) | This pattern validates a 10-digit mobile number, optionally preceded by +91 or 0. Example: `9876543210` or `+919876543210` (valid mobile number formats) |
U.S. Postal Code | This pattern validates the common 5-digit U.S. postal code format. Example: `12345` (valid U.S. postal code) |
U.S. State | This pattern allows common U.S. state names. Example: `California` (valid U.S. state name) |
Phone Number ((xxx) xxx-xxxx format) | This pattern verifies the common (xxx) xxx-xxxx phone number format. Example: `(123) 456-7890` (valid phone number format) |
Social Security Number (xxx-xx-xxxx format) | This pattern validates the common xxx-xx-xxxx Social Security number format. Example: `123-45-6789` (valid Social Security number format) |
MAC Address | This pattern checks for the common MAC address format, separated by colons or hyphens. Example: `00:1A:2B:3C:4D:5E` (valid MAC address format) |
IP Address (both IPv4 and IPv6) | This pattern verifies both IPv4 and IPv6 address formats. Example: `192.168.1.1` or `2001:0db8:85a3:0000:0000:8a2e:0370:7334` (valid IP address formats) |
Credit Card (xxxx-xxxx-xxxx-xxxx) | This pattern validates a 16-digit credit card number format, separated by hyphens. Example: `1234-5678-9012-3456` (valid credit card number format) |
Regex criteria are special patterns that match the user input precisely. This regex criteria is used to find, validate, or replace specific patterns of characters in a chunk of text. Before looking into regex in layout and validation rules, let's cover the different regex criteria available.
- When to use: The Contains Regex option is used when a user wants to find or validate data that contain a specific pattern.
- What Can Be Achieved: This option allows user to identify instances where a particular pattern exists within the provided text. Consider an online marketplace where sellers list products. To ensure accurate shipping information, you want to identify product listings that mention U.S. postal codes. By using Contains Regex, you can automatically detect listings that reference the five-digit format of U.S. postal codes.
Points to Remember
Layout rules are used to define dependency between fields or sections based on the user's input. So, when a user fills in a field, the layout progressively adds more fields or sections based on the user's input. In general, layout rules can be used to define the dynamic behavior of the layout based on a value entered in a field. See also: Creating Layout Rules in Zoho Desk.
While configuring layout rules, regex can be set on the primary field so that the value can be validated when entered by the user. This can be useful in determining the layout behavior based on the format of the data given and eliminates the need to create several criteria.
For example, in a product purchase form a user needs to fill the credit card number, based on which a section with fields such as expiry date, card holder's name etc. is displayed. With regex, the credit card number format and pattern can be validated so that users fill a valid 16-digit number. If the field value is incorrect, the dependent section will not be displayed.
You can create a layout rule using the below regex criteria:
Credit card number + Contains Regex + Credit Card Number
To create a layout rule using regex
Using regex in validation rules, helps ensure that only those records where the user's input matches the specific pattern are saved in the system. This was, organizations can prevent invalid inputs.
For example, let's say you want to validate whether an end user enters an email address in a specific format, such as johnsmith123@zylker.com. In such a case, you can create a validation rule and define or choose a regex pattern that matches the format of a valid email address (Such as Email + Matches Regex + Email Address). This pattern can then be used to check whether the entered email address matches that format.
Likewise, you can also create a regex pattern that matches email addresses ending with the zylker [your desired] domain.
(?i)[a-z0-9.-]+@zylker\.com$
In this pattern, (?i) is a modifier that makes the pattern case-insensitive. This regular expression allows for alphanumeric characters (lowercase), periods, and hyphens in the email username. It then matches the literal string "@zylker.com", and the $ symbol specifies that the match must end with the domain name "zylker.com".
To create a validation rule using regex
Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.
If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.
You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.