What is the regex for email list on the Salesforce validation rule?

170    Asked by ClaudineTippins in Salesforce , Asked on Mar 1, 2023

For simplicity sake, I will edit my question to have emails separated with just semicolon e.g. 213@aaa.com;424@www.com


So I have this Long Text Area field to capture multiple email addresses inside like :


abc@xyz.com; ac_cs@asd.com

And I want to create a Salesforce Validation rule to ensure email lists are well formed separated by ; or ,.


I tried using the Regex I found on this exchange and other sites to come up with :

NOT(REGEX(CS_Email_List__c  ,"(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])"))
Answered by David Edmunds

After building my regex for email on https://regex101.com/.. I managed to come up with a single line regex that helped me.


This might not cover all email cases but it does for all my tests.

NOT(
  REGEX(
     CS_Email_List__c ,
     '([a-z0-9_-]+@[a-z0-9_-]+.[a-z0-9_-]+(;{1}[a-z0-9_-]+@[a-z0-9_-]+.[a-z0-9_-]+)+)*'
   )
)

Your Answer

Interviews

Parent Categories