function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Carsten BONOMOCarsten BONOMO 

Regex usage in formula field

Hi All, 

I'm currently trying to use a REGEX operator in a formula field. This is my code : 

IF(
  OR(
    REGEX((SUBSTITUTE(Contact_Phone__c," ","")), "[0-9]{12}"),
    REGEX((SUBSTITUTE(Contact_Phone__c," ","")), "[0-9]{11}")
    ),
  SUBSTITUTE(Contact_Phone__c," ",""),
  ""
  )

This is the error I get : Function REGEX may not be used in this type of formula (Related field: Formula)

But on the documentation page (https://help.salesforce.com/articleView?id=customize_functions_i_z.htm&type=5) it seems like I can use REGEX in a formula field. 

Many thanks for any explanation !
Best Answer chosen by Carsten BONOMO
Alain CabonAlain Cabon
Hi,

REGEX: This function is available everywhere formulas exist except formula fields and custom buttons and links.
https://help.salesforce.com/articleView?id=customize_functions_i_z.htm&type=5

... almost everywhere.

You can use a validation rule with regex.

All Answers

Alain CabonAlain Cabon
Hi,

REGEX: This function is available everywhere formulas exist except formula fields and custom buttons and links.
https://help.salesforce.com/articleView?id=customize_functions_i_z.htm&type=5

... almost everywhere.

You can use a validation rule with regex.
This was selected as the best answer
Timo BierbrauerTimo Bierbrauer
I can't....why? Again and again I'm cursing this system missing basics....
Bharath Goud 10Bharath Goud 10
REGEX FORMULA SYNTAX ERROR

HOW TO CREATE A REGEX TO MAKE A VALIDATION RULE THAT THE FIRST LETTER OF THE FIELD ENTRY SHOULD BE A CAPITAL LETTER.