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
Claire NicolayClaire Nicolay 

REGEX in Workflow rule

Hi, I have a validation rule for the phone number to be 10 characters as follows xx xx xx xx xx
To make things quicker and easier for the users, I would like to replace my validation rule by a workflow rule, so I defined that, if the field "MobilePhone", which is phone format, is not empty, then the field should be updated using the following formula:
REGEX(  MobilePhone  , "[0-9]{2} [0-9]{2} [0-9]{2} [0-9]{2} [0-9]{2}")

I get the following error message: formula result is data type(Boolean) not compatible with the expected data type (Texte)

Can somebody help to make this worklfow field update work? Thanks!
Best Answer chosen by Claire Nicolay
Apoorv Saxena 4Apoorv Saxena 4
Hi Claire,

You cannot update a MobilePhone field through REGEX() function as REGEX returns a boolean value either TRUE or FALSE.

Syntax: REGEX(Text, RegEx_Text)
Returns TRUE if Text matches the regular expression RegEx_Text. Otherwise, it returns FALSE.

Hence the error, because its expecting to return some text, but its getting a boolean value(i.e either True or False)

Your best bet is using a validation rule for this as you were using it earlier, but if you want to format the mobilephone field automatically then you'll have to write an apex trigger.

Hope this helps!

Thanks,
Apoorv

All Answers

Apoorv Saxena 4Apoorv Saxena 4
Hi Claire,

You cannot update a MobilePhone field through REGEX() function as REGEX returns a boolean value either TRUE or FALSE.

Syntax: REGEX(Text, RegEx_Text)
Returns TRUE if Text matches the regular expression RegEx_Text. Otherwise, it returns FALSE.

Hence the error, because its expecting to return some text, but its getting a boolean value(i.e either True or False)

Your best bet is using a validation rule for this as you were using it earlier, but if you want to format the mobilephone field automatically then you'll have to write an apex trigger.

Hope this helps!

Thanks,
Apoorv
This was selected as the best answer
Claire NicolayClaire Nicolay
Thanks Apoorv,but I would like to avoid using a validation rule and avoid using apex as well
Was hoping there is a solution using a WF and field update to ensure the phone number looks as follows : 11 11 11 11 11
Apoorv Saxena 4Apoorv Saxena 4
Hi Claire :

Try using this formula  in your workflow field update action :

MID(TEXT(VALUE(Phone)),1,2)
+' '+MID(TEXT(VALUE(Phone)),3,2)
+' '+MID(TEXT(VALUE(Phone)),5,2)
+' '+MID(TEXT(VALUE(Phone)),7,2)
+' '+MID(TEXT(VALUE(Phone)),9,2)

Hope this helps!

Please let me know how this works for you, mark this as Solved if this helps you so that others can view it as a proper solution.

Thanks,
​Apoorv
Claire NicolayClaire Nicolay
Hi, will stick with the validation rule in the end. thanks for your help