Print this page

Common REGEX Validation

Knowledge Article Number 000213868
Description The following table describes commonly-requested REGEX-based validation rules.
Resolution Note: In the following table, "_" denotes an optional space (the REGEX will accept it with or without the space)
American Phone Number (no extension)(999)_999-9999
American Phone Number (w/extension)The above formats, plus:
(any length of extension)
Accepts : or . after ext or x, and accepts +1 in front of number.
Social Security Number999-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
Brazilian Phone Number (no extension)(99)_9999-9999
+55 (99)_9999-9999
+55 (99)_99999-9999
Brazilian Phone Number (w/Extension)The above formats, plus the following:
[phone like above] ramal: 999…
[phone like above] ramal 999…
Brazilian CNPJ (business tax Id)99.999.999/9999-99!REGEX(CNPJ__c,"^(\\d{2}\\.\\d{3}\\.\\d{3}/\\d{4}\\-\\d{2})?$")
Brazilian CPF999.999.999-99!REGEX(CPF__c,"^(\\d{3}\\.\\d{3}\\.\\d{3}\\-\\d{2})?$")
Brazilian Post code (5 or 8 digit)99999-999
Brazilian CPF999.999.999-99!REGEX(CPF__c,"^(\\d{3}\\.\\d{3}\\.\\d{3}\\-\\d{2})?$")
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.
John de Souza
Rio de Janeiro
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 which supports multiple lines. ¹
REGEX( ShippingStreet , '(.*\r?\n.*)*')
Allow for a maximum of three lines in a text field which supports multiple lines. ¹
REGEX( ShippingStreet , '(.*\r?\n.*){3,}')
  1. When editing a field, depending on how you edit, and depending on your browser, either just a Line Feed is inserted ( ' \n ' ) or a Carriage Return ( ' \r ' ) and a Line Feed ( ' \n ' ). Therefore we need to check for, no or one Carriage Return ( ' \r? ' ), followed by a Line Feed ( ' \n ' ).

See also:
Formula Operators and Functions I–Z : REGEX

promote demote