Tips for commonly requested field validation that uses the REGEX() function.
Note: In the following table, "_" denotes an optional space (the REGEX will accept it with or without the space).
| Description | Formats | Validation |
|---|---|---|
| American Phone Number (no extension) | (999)_999-9999 +1_(999)_999-9999 | !REGEX(Phone,"^((\\+1)?\\s?\\(\\d{3}\\)\\s?\\d{3}\\-\\d{4})?$") |
| American Phone Number (w/extension) | The above formats, plus: (999)_999-9999_x999… (999)_999-9999_Ext._999… (999)_999-9999_ext:_999… (any length of extension) Accepts : or . after ext or x, and accepts +1 in front of number. | !REGEX(Phone,"^((\\+1)?\\s?\\(\\d{3}\\)\\s?\\d{3}\\-\\d{4}(\\s?(x|([Ee]xt[\\.:]?\\s?))\\d+)?)?$") |
| Social Security Number | 999-99-9999 | !REGEX(Social_Security_Number__c,"^(\\d{3}\\-\\d{2}-\\d{4})?$" |
| American ZIP code (5 digit) | 12345 | !REGEX(PostalCode,"^\\d{5}?$") |
| American ZIP code (5 or 9 digit) | 12345 12345-6789 | !REGEX(PostalCode,"^(\\d{5}(\\-\\d{4})?)?$") |
| Brazilian Phone Number (no extension) | (99)_9999-9999 (99)_99999-9999 +55 (99)_9999-9999 +55 (99)_99999-9999 | !REGEX(Phone,"^((\\+\\d{2}\\s)?\\(\\d{2}\\)\\s?\\d{4}\\d?\\-\\d{4})?$") |
| Brazilian Phone Number (w/Extension) | The above formats, plus the following: [phone like above] ramal: 999… [phone like above] ramal 999… | !REGEX(Phone,"^((\\+\\d{2}\\s)?\\(\\d{2}\\)\\s?\\d{4}\\d?\\-\\d{4}(\\sramal:?\\s\\d+)?)?$") |
| Brazilian CNPJ (business tax Id) | 99.999.999/9999-99 | !REGEX(CNPJ__c,"^(\\d{2}\\.\\d{3}\\.\\d{3}/\\d{4}\\-\\d{2})?$") |
| Brazilian Post code (5 or 8 digit) | 99999-999 99999 | !REGEX(PostalCode,"^(\\d{5}(\\-\\d{3})?)?$") |
| Brazilian CPF | 999.999.999-99 | !REGEX(CPF__c,"^(\\d{3}\\.\\d{3}\\.\\d{3}\\-\\d{2})?$") |
| Japanese Phone Number (no extension) |
99-9999-9999 |
!REGEX(Phone,"^[0-9]{2,4}-[0-9]{2,4}-[0-9]{3,4}$") |
|
Japanese ZIP code ("-" is required) |
999-9999 |
!REGEX(PostalCode,"^[0-9]{3}-[0-9]{4}$") |
|
Japanese ZIP code (with or without "-") |
999-9999 |
!REGEX(PostalCode,"^([0-9]{3}-[0-9]{4})?$|^[0-9]{7}+$") |
| Title Case words and Names Covers all accents listed in the regex, and enforces Title Case (First letter capitalized, the rest lowercase) except special words (in some languages), da, de, di, do, and the d' prefix. | Smith John de Souza Rio de Janeiro Brasília d'Onofrio di Lorenço | !REGEX(FirstName, "^((^|\\s)(((([DdO]')|Mc|Mac)?[A-ZÃÁÂÀÄÇÉÈÊËÍÌÎÏÕÒÔÓÖÛÚÙÜ][a-zãáàâäçéèêëíìîïñõôóòöûúùü]*)|(da|de|di|do)))*$") |
| Prevent users to enter a line break in a text field that supports multiple lines. ¹ |
REGEX( ShippingStreet , '(.*\r?\n.*)*') | |
| Allow for a maximum of three lines in a text field that supports multiple lines. ¹ |
REGEX( ShippingStreet , '(.*\r?\n.*){3,}')
| |
For assistance with a REGEX formula not listed here, visit the Trailblazer Community.
000386675

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.