Regex Function in salesforce

Regex Function in salesforce

The double backslashes are used because of Javas string escaping rules. The pure regex means:

D*?   # Match any number of non-digit characters (the ? is useless here)
(      # Match...
 d    # a single digit
 D*?  # optionally followed by any number of non-digits (again, useless ?)
){10}  # Repeat the previous group 10 times.

So this regex matches any string that contains exactly ten digits (plus any number of other, non-digit characters).

If youre using the REGEX from the example in Salesforce, its useless. It matches this1234567890that where this and that can be any value. I used: NOT( REGEX(Phone, ([0-9]{3}) [0-9]{3}-[0-9]{4}|d{10})) to accomplish the desired behavior.

My version translates to:

\(      # Match (
[0-9]{3} # Match 3 digits
\)      # Match ) followed by a space 
[0-9]{3} # Match 3 digits
-        # Match hyphen
[0-9]{4} # Match 4 more digits
|\d{10} # or match 10 digits instead of all the previous

Regex Function in salesforce

Leave a Reply

Your email address will not be published.