Regex in Layout and Validation Rules

Regex in Layout and Validation Rules

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:

 

  • Increase efficiency: Regex makes it easier to find specific patterns in a large amount of data.
  • Improve data identification: Regex allows to specify the exact pattern reducing the possibility of missing or misidentification of data.
  • Facilitate reusability: Once you have created a regex pattern, you can reuse the same pattern in different contexts.
  • Maintain data accuracy: Regex can be used to validate the input data and ensure that it meets certain criteria before processing it further.

 

Some common instances where regex can be useful in validating user's input: 

  1. Email addresses: Regex can be used to validate the format of an email address. For example, the below regex pattern can be used to validate if an email address has the "@" symbol and the domain name in the right sequence. 
    ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

  2. Account numbers: Regex can be used to validate bank account numbers. Here's an example of a regex pattern to validate a U.S. bank account number:
    ^\d{1,17}$
    The above pattern will check whether the account numbers contain 1-17 digits.

  3. Password Strength: Regex can also be used to validate the strength of passwords. For example, the following regex pattern can be used to check for a strong password:
    ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^\w\d\s:])([^\s]){8,16}$
    This regex pattern checks for a password that contains at least one digit, one lowercase letter, one uppercase letter, one special character, and is between 8 and 16 characters long.

Permission Required
Users with the Manage Layout and Fields permission within the Administrative permission can access this feature.
Check Feature Availability and Limits
 

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.
Example: `https://www.example.com` (valid URL format)

Email ID
This pattern ensures the input follows a standard email format.
Example: `user@example.com` (valid 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 

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.

  1. Matches Regex:

    1. When to use: This option is used when a user want to find data that precisely match a specific pattern defined using regex.
    2. What can be achieved: Matches Regex can be used to search for data that adhere to a very specific and defined pattern. For example, you could use it to find if all email addresses matches a particular alphanumeric pattern.

  2. Not Matches Regex:

    1. When to use: Not Matches Regex is helpful when a user wants to filter out data that match a particular regex pattern.
    2. What can be achieved: This option excludes data that meet a specific pattern. For instance, you might want to exclude usernames entries that contain special characters. By applying Not Matches Regex, you can easily avoid the usernames that don't align with your desired pattern.

  3. Contains Regex:
  1. When to use: The Contains Regex option is used when a user wants to find or validate data that contain a specific pattern.
  2. 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

 

  • A layout/validation rule can have five primary conditions, and each condition can have a separate regex criteria.
  • You cannot add the regex criteria for secondary conditions in layout and validation rule.





  • While defining the regex criteria, you can either manually create a custom regex pattern or select a pattern from the regex gallery.


Using  Regex in layout rules 

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 

  1. Navigate to Setup (  ) > Customization > Layout and Fields.
  2. Select Layout Rules from the left pane.
  3. Click Create Rule in the upper-right corners.



  4. In the Create Layout Rule window, do the following:
    1. Enter the rule name.
    2. Give a Description for the rule.
    3. Select the desired Layout.
    4. Choose a Primary field that controls this rule.
    5. Choose a Condition to initiate the rule. 
    6. Select the desired regex criteria. 
    7. You can choose from Matches RegexNot Matches Regex, and Contains Regex (For example: Credit card Number + Contains Regex + Credit Card Number).
    8. Click Next.



  5. In the Create Layout Rule Editor, click Trigger an action and choose the desired actions from the list.
  6. In the Create Action page, click Show FieldsShow Sections, and Set Mandatory Fields, then select the respective fields.
  7.  Click Done.
    Actions in Layout Rule.
  8. Check Apply to Help Center to manage dependencies between fields when tickets are submitted through your help center.
  9. Click Save.



Using Regex in validation rules 

Validation rules ensures that valid data enters the system. If the value is incorrect, an error message prompts the user to rectify before saving the record. See also: Creating Validation Rules in Zoho Desk.

 

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 

 

  1. Navigate to Setup (  ) > Customization Layout and Fields.
  2. Select Validation Rules from the left pane.
  3. Click Create Rule in the upper-right area



  4. In the New Validation Rule window, do the following:
    1. Select the desired Layout.
    2. Choose a primary field that controls this rule.
    3. Click Next.
  5. In the Create Validation Rule editor, click Add Another Option and specify the regex criteria to validate.
    You can choose from Matches RegexNot Matches Regex, and Contains Regex. For example: Email Matches Regex + Email Address.
  6. Click Done.





  7. Specify the necessary Alert message.



  8. Check Apply to Help Center to validate tickets submitted through your help center.
  9. Click Save.

 

Note: You can either disable or delete the layout or validation rule when not in use. When you delete a rule, it will be permanently removed and cannot be recovered.



    Access your files securely from anywhere

      Zoho CRM Training Programs

      Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

      Zoho CRM Training
        Redefine the way you work
        with Zoho Workplace

          Zoho DataPrep Personalized Demo

          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.

          Zoho CRM Training

            Create, share, and deliver

            beautiful slides from anywhere.

            Get Started Now


              Zoho Sign now offers specialized one-on-one training for both administrators and developers.

              BOOK A SESSION









                                            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.




                                                Manage your brands on social media

                                                  Zoho Desk Resources

                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                    Zoho Marketing Automation

                                                      Zoho Sheet Resources

                                                       

                                                          Zoho Forms Resources


                                                            Secure your business
                                                            communication with Zoho Mail


                                                            Mail on the move with
                                                            Zoho Mail mobile application

                                                              Stay on top of your schedule
                                                              at all times


                                                              Carry your calendar with you
                                                              Anytime, anywhere




                                                                    Zoho Sign Resources

                                                                      Sign, Paperless!

                                                                      Sign and send business documents on the go!

                                                                      Get Started Now




                                                                              Zoho TeamInbox Resources



                                                                                      Zoho DataPrep Resources



                                                                                        Zoho DataPrep Demo

                                                                                        Get a personalized demo or POC

                                                                                        REGISTER NOW


                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now









                                                                                                              • Related Articles

                                                                                                              • Creating Validation Rules

                                                                                                                Go to any website with a registration form, and you will notice that they provide you feedback when you don't enter your data in the format they are expecting. For example, when the phone number field on a form is not filled in or does not contain 10 ...
                                                                                                              • Understanding Layouts and Layout Rules

                                                                                                                Creating Layouts Layouts control the organization of fields and related sections on the module page of a department. Each department can have its own layout that consists of both default and custom fields. They also determine which fields are ...
                                                                                                              • FAQs: Validation Rules

                                                                                                                How to create validation rules? To create a validation rule in Zoho Desk, follow the steps given below: Go to Setup > Customization > Layouts and Fields > Validation Rules. In the Validation Rules page, select the required module and the department ...
                                                                                                              • FAQs: Assignment Rules

                                                                                                                What is an assignment rule and why do I need it? Assignment rule is an automation tool that lets the support administrator automate the process of assigning tickets to agents. Customer support is a crucial job, and timely and effective resolution of ...
                                                                                                              • Assigning Tickets using Workflow and Assignment Rules

                                                                                                                We are opening the 'Agent level threshold' on a request basis. Kindly raise a request using the Early Access Form. Availability Permission Required Users who have the Help Desk Automation permission enabled in their profile can create workflows and ...
                                                                                                                Wherever you are is as good as
                                                                                                                your workplace

                                                                                                                  Resources

                                                                                                                  Videos

                                                                                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                  eBooks

                                                                                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                  Webinars

                                                                                                                  Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                  CRM Tips

                                                                                                                  Make the most of Zoho CRM with these useful tips.



                                                                                                                    Zoho Show Resources