4

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
  • 2
    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
    Commented May 31, 2019 at 16:11

1 Answer 1

8

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})') 
) 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .