I'm trying to write a validation rule for phone numbers with extensions. I want to be sure there are exactly 10 integers to the left of the letter "x". It needs to ignore special characters and only count integers.

I can't find a useable REGEX formula for this. I can use the FIND function to find the "x" but I'm not sure how to count the number of integers to the left of it.

This is the format numbers will be in: (999) 999-9999 x123. Right now, the system allows something like this (999) 999-99999999 x123.

  • I'd say that this is a problem well-suited for regex. Not so much counting that there are X numbers, but validating that the overall text follows a specific format. Have you tried to create your own regex to handle this, or did you just look for regex that other people have composed? If you have tried to create your own regex, please share that with us. If you're not familiar with writing regex, this seems like a good opportunity to start learning.
    – Derek F
    Commented Aug 29, 2019 at 17:18
  • @DerekF I've looked into writing REGEX, but I couldn't find any good documentation for how to understand it. I spoke with a few developers and they said it's not easy to understand and isn't always reliable.
    – Rochelle C
    Commented Aug 29, 2019 at 17:25

1 Answer 1


I think I figured it out. I isolated the portion before the "x" and ran REGEX on that.


NOT(CONTAINS(Phone_Number__c, "x")), 
NOT(REGEX(Phone_Number__c, "\\D*?(\\d\\D*?){10}")) 

**CONTAINS(Phone_Number__c, "x"), 
NOT(REGEX(LEFT(Phone_Number__c, FIND("x", Phone_Number__c)), "\\D*?(\\d\\D*?){10}"))**


You must log in to answer this question.

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