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
Firas Taamallah 18Firas Taamallah 18 

How to test if Text field contain less than 5 email addresses? APEX

Hello , 

I have text field in Case , i want to test if this field contain less than 5 email addresses - How can i acheieve this?

Thanks,
Firas
Suraj Tripathi 47Suraj Tripathi 47

Hi Firas,

Please find the solution. "How to test if Text field contain less than 5 email addresses? APEX"

one email can contain one @ so 5 emails can contain 5 emails. We can do one thing we can count the number of @ from the string.

Please check the below  code
 

String searchString='abc@gmail.com;a@gmail.com,amit@gmail.com';
system.debug('***'+searchString.countMatches('@'));  //3@=> 3 emails

You can also take references from the below link.

https://developer.salesforce.com/forums/?id=9062I000000XnKdQAK

https://salesforce.stackexchange.com/questions/130647/apex-count-the-number-of-letters-in-an-arbitrary-string

Please mark this solution as the Best Answer so that other people can also take references from this here.

Thank You