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
JGFJGF 

Use a formula to create a dynamic Regex for a Flow validation

Hello everyone.

I'm trying to create a regex that is created on the fly given two values of the record's two fields. This regex will be used as a validation of a text field input at a Flow.

For this I'm thinking of creating a Formula Text variable with the following content;
\\-?\\d{1,{!nextRecord.First_Field__c}}(\\,\\d{0,{!nextRecord.Second_Field__c}})?
If I place it like that, saving will tell me that de syntax is wrong. By placing it between quotes it allows me to activate de flow.
"\\-?\\d{1,{!nextRecord.First_Field__c}}(\\,\\d{0,{!nextRecord.Second_Field__c}})?"
When I get to the display where I have the field input, the regex seems to arrive with the literal of the field I placed instead of being replaced with the value of those fields, something like this;
\-?\d{1,nextRecord.First_Field__c}(\,\d{0,nextRecord.Second_Field__c})?-1
The Regex with this value is not working.
Any way to be able to create this kind of regex where I can put a Field value into it?

Thank you very much.

 
Best Answer chosen by JGF
JGFJGF
I just found how I should do it. I have to put the field I want as a separate part of the formula that will be used with the Text function so the final result is the regex i wanted!
"\\-?\\d{1," + TEXT({!nextrecord.First_Field__c}) + "}(\\,\\d{0,"+ TEXT({!nextRecord.Second_Field__c})+"})?"
Will give
\-?\d{1,7}(\,\d{0,3})?

Thank you very much.