0

**UPDATE 22 June 2022

For simplicity sake, I will edit my question to have emails separated with just semicolon e.g. [email protected];[email protected]


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

[email protected]; [email protected]

And I want to create a Salesforce Validation rule to ensure email list 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])+)\\])"))

But I can never get it correct. Help pls?

2 Answers 2

1

Try with below validation rule separated by comma(,) or semi colon(;).

OR(
AND(NOT(
REGEX( CS_Email_List__c , "([a-zA-Z0-9._-]+@[a-zA-Z]+.[a-zA-Z,]{2,4})*")
),
NOT(
REGEX( CS_Email_List__c , "([a-zA-Z0-9._-]+@[a-zA-Z]+.[a-zA-Z;]{2,4})*")
)),
AND(RIGHT( CS_Email_List__c  , 1 ) = ",",

RIGHT( CS_Email_List__c , 1 ) = ";")


)
2
0

After building my regex 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_-]+)+)*'
   )
)

You must log in to answer this question.

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