Skip to content

Use regular expressions to validate property values (BETA)

Last updated: December 11, 2024

Available with any of the following subscriptions, except where noted:

Marketing Hub   Professional , Enterprise
Sales Hub   Professional , Enterprise
Service Hub   Professional , Enterprise
Operations Hub   Professional , Enterprise
Content Hub   Professional , Enterprise

To improve the consistency and quality of your CRM data, you can use regular expressions (regexes) to validate text property values. Regexes are sequences of characters that define a desired text pattern. For example, you can require values with a certain number of digits or include specific characters and formatting.

In this article, learn how to add regular expressions to a property's validation rules and review example use cases.

Please note: HubSpot's regex engine does not support capture groups. You can use regular expressions for pattern matching, but you won't be able to use features associated with capture groups, such as the following: extracting parts of the match for later use, referring back to captured values within the expression (i.e. backreferences), or storing match results in variables or groups.

Add regex validation rules to a property

  • In your HubSpot account, click the settings settings icon in the top navigation bar.
  • In the left sidebar menu, navigate to Properties.

  • Click the Select an object dropdown menu, then select [Object] properties to create or edit a property for that object.

  • Create or edit a property with the Single-line text or Multi-line text field type.
  • In the property editor, navigate to the Rules tab.
  • To set up validation using regular expressions, select Validate using regular expression (regex). If you want to use simple rules instead, learn how to set up other validation rules.
  • Enter your regular expression in the Regex field.
  • Enter an error message in the Invalid value message field. This is displayed to users when the value they've entered doesn't meet the validation requirements.
  • To add more detail to your error message, enter an optional additional help message.
  • To test the validation, enter a value. If the regex works, an invalid value will result in an error, while a valid value will be accepted.

regex-validation

  • Finish setting up or editing your property, then click Create or Save.

The validation rules apply when users set or edit the property's value during creation, on a record, on the object index page, via import, or through submissions to forms created via the new form editor.

Regex syntax

For guidance setting up your regular expression, refer to this Regex cheat sheet.

Example expressions

Some example use cases include:

Please note: before implementing the following expressions, you should verify they work for your specific use case.

  • US phone number: to require that phone numbers are entered in the format (123) 456-7890, you could use the regex ^\(\d{3}\) \d{3}-\d{4}$.
  • Email address: to validate that an inputted value follows a standard email format (e.g., user@example.com), you could use the regex ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$.
  • Zip code: to require that zip codes have five digits, you could use the regex ^\d{5}$.
  • URL: to validate a URL starts with "http://" or "https://"”, you could use the regex ^https?:\/\/[^\s/$.?#].[^\s]*$.
  • No whitespace: to prevent whitespaces from being entered, you could use the regex ^\S*$
Was this article helpful?
This form is used for documentation feedback only. Learn how to get help with HubSpot.