+ 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....