3

This is my regex (for international phone number), i have the message "Syntax Error" with this part of regex highlighted :

s*[)]?[-\s.]?[(]?[0-9]{1,3}[)]?([-\s.]?[0-9]{3})([-\s.]?[0-9]{3,4})')

This is the regex and the regex tester online : https://www.regextester.com/97440

AND(
    $Setup.ActivationSettings__c.VR_Contact__c,
    OR(
        AND(
            !ISBLANK( Phone ),
            !REGEX( Phone , '(([+][(]?[0-9]{1,3}[)]?)|([(]?[0-9]{4}[)]?))\s*[)]?[-\s\.]?[(]?[0-9]{1,3}[)]?([-\s\.]?[0-9]{3})([-\s\.]?[0-9]{3,4})')
        ),
        AND(
            !ISBLANK( MobilePhone ),
            !REGEX( MobilePhone , '(([+][(]?[0-9]{1,3}[)]?)|([(]?[0-9]{4}[)]?))\s*[)]?[-\s\.]?[(]?[0-9]{1,3}[)]?([-\s\.]?[0-9]{3})([-\s\.]?[0-9]{3,4})')
        )
    )
)

Thanks

1
  • 1
    While regex is something that would generally be suited for SO, there are nuances here leading to the error that are very much Salesforce-specific (as the answer identifies). Thus, this question should remain open.
    – Derek F
    May 31 '19 at 16:11
7

Escape the \ with an extra \ . Like below:

AND( 
!ISBLANK( Phone ), 
!REGEX( Phone , '(([+][(]?[0-9]{1,3}[)]?)|([(]?[0-9]{4}[)]?))\\s*[)]?[-\\s\\.]?[(]?[0-9]{1,3}[)]?([-\\s\\.]?[0-9]{3})([-\\s\\.]?[0-9]{3,4})') 
), 
AND( 
!ISBLANK( MobilePhone ), 
!REGEX( MobilePhone , '(([+][(]?[0-9]{1,3}[)]?)|([(]?[0-9]{4}[)]?))\\s*[)]?[-\\s\\.]?[(]?[0-9]{1,3}[)]?([-\\s\\.]?[0-9]{3})([-\\s\\.]?[0-9]{3,4})') 
) 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.