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
Rashed Yaqubi 10Rashed Yaqubi 10 

Validation Rule with Regex Statement: 10digit numbers separated by commas

Hey guys, there is a text field that I want to restrict so it only accepts 10 digit phone numbers separated by commas. 

So far I have this, but it does not specify how many digits the numbers must be.  So it allows any number of digits separated by commas (i.e. 123,12,1234,12345,etc).  But I want to restrict it to comma separated 10-digit numbers (i.e. 4161231234,6470987657,9051231234,etc…).  I know I need a “{10}” somewhere, but can’t seem to figure out where. 

Your help is greatly appreciated.


AND(
NOT(ISBLANK(Text_Field__c)),
NOT(REGEX(Text_Field__c,"^[0-9,.*]+$"))
)
Best Answer chosen by Rashed Yaqubi 10
Alain CabonAlain Cabon
 
NOT(REGEX(Text_Field__c,"^([0-9]{10}?(,|$))+"))

 

All Answers

AnudeepAnudeep (Salesforce Developers) 
See Common REGEX Validation

American Phone Number (no extension) is 10 digits

!REGEX(Phone,"^((\\+1)?\\s?\\(\\d{3}\\)\\s?\\d{3}\\-\\d{4})?$")

 
Rashed Yaqubi 10Rashed Yaqubi 10
Thanks Anudeep, but that does not solve my problem.  I want the user to be able to enter 10-digit numbers (no area code, dashes, brackets or spaces) separated by commas into a TEXT field.
Alain CabonAlain Cabon
 
NOT(REGEX(Text_Field__c,"^([0-9]{10}?(,|$))+"))

 
This was selected as the best answer
Rashed Yaqubi 10Rashed Yaqubi 10
Thank you Alain, this worked! 

If I wanted to allow spaces after the commas, how would this REGEX statement look? i.e 1231231234, 3213213214, 1231231234, etc..
Alain CabonAlain Cabon
There is exactly one space and always one space:  
NOT(REGEX(Text_Field__c,"^([0-9]{10}?(, |$))+"))

There are no space or many spaces:  
NOT(REGEX(Text_Field__c,"^([0-9]{10}?(,[ ]*|$))+"))

There are at least one space:  
 
NOT(REGEX(Text_Field__c,"^([0-9]{10}?(,[ ]+|$))+"))


 
Rashed Yaqubi 10Rashed Yaqubi 10
Super helpful Alain, appreicate it!