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
BrenzoBrenzo 

Validation Rule to Check for Multiple, Repeating Text strings

I have a custom textarea field where a user could input multiple email addresses that are then pulled into an email template via a button that refers to this field. 

What I am attempting to do is fire a validation rule if more than one '@' symbol is found and no comma (',') is present. The idea being that if the user wants to insert multiple email addresses then it'll prompt them to ensure these are separated via comma. The reason for doing this vs. creating mutliple lookup or email fields is that there may be instances where a user wants to include multiple (5+ recipents) and I do not want to waste fields or space on the page layout for all these individual fields and would rather just have one section.

Even better would be a rule that would look for & count how many '@' symbols appear and then make sure there are the same number of corresponding commas (well, actually one less since you do not need a comma at the end.)

The validation rule would then state something along the lines of "Please separate multiple email addresses with a comma."

I appreciate in advance any help that anyone can provide!
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Not sure about validation rule but you can do it in apex by using countMatches(substring) function. 
If(Text_Area__c.countMatches('@')-Text_Area__c.countMatches(',')!=1, then add error.
BrenzoBrenzo
I was worried about that as I am not that familiar or comfortable with writing Apex...
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Just create a trigger with this code, replace field names and object
trigger validateEmailAddresses on Account (before insert, before update) {
    for(Account acc: trigger.new){
        if(acc.Multiple_Email_Addresses__c.countMatches('@')-acc.Multiple_Email_Addresses__c.countMatches(',')!=1)
            acc.addError('Please correct the email addresses');
    }
}