+ Start a Discussion

Validation rule to allow multiple email id's separated by comma in text field?

Hi All,
Can some one help me with the validation rule for  entering mutiple email addresses seperated by comma?

I am trying to achieve basic validation for email as i am using text field(255) to enter mutiple email id's plus to ensure that  multiple email addresses has to have each address separated by a comma
and if only one email address is present in the text box no need of using comma.
I know regex function is used for basic validation of email. But how do i combine regex function and the logic that two email addresses should be seperated by comma.
Thanks in advance
ShashankShashank (Salesforce Developers) 
You can probably use the fact that every email address has atleast one "@" character. So, you can count the number of "@" characters and forces as many comma characters as the number minus one.

If there are 'n' occurances of the "@" character, you can check if there are 'n-1' comma characters. This may not be the perfect approach, but the best I could think. However, I highly doubt whether this can be done using a validation rule, so you may have to go for an apex trigger.
I found
REGEX:  NOT( REGEX(Custom_email_list__c , "([A-Za-z0-9]+([!#$%&'*+-/=?^_`{|}~]*[A-Za-z0-9]+)*@[A-Za-z0-9\\-]+(\\.[A-Za-z0-9\\-]+)*[ ]*[,;]?[ ]*)+" ))
can we change the above expression so that we can make comma mandatory when one email address is followed by another
and also if there is a single email address in the field comma is not mandatory.

Sonya Dhand 14Sonya Dhand 14
Can anyone help with the question above.  I too need to validate if multiple email address text has a ; between each address

Thanks in advance