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
Sonya Dhand 14Sonya Dhand 14 

Regex Validation help to ensure ; separates multiple email addresses in a long text field?

Hi

I am using the following to validate an text field has email addresses entered in the correct format.  However I also need to ensure between each email address there is a ; seperator  

The regex I found onlne is :

NOT( REGEX(Custom_email_list__c , "([A-Za-z0-9]+([!#$%&'*+-/=?^_`{|}~]*[A-Za-z0-9]+)*@[A-Za-z0-9\\-]+(\\.[A-Za-z0-9\\-]+)*[ ]*[,;]?[ ]*)+" ))

which works well but still works without a ; between email addresses

How do I ensure ; is present and if not it will throw the validation error?

Many thanks in advance
NagendraNagendra (Salesforce Developers) 
Hi Sonya,

May I request you please check with below links from the community forums which will point you in the right direction. Hope this helps.

Please mark this as solved if it's resolved.

Thanks,
Nagendra
Sonya Dhand 14Sonya Dhand 14
Hi I have already referred to these posts. You will see I actually added a comment to one of them a few days ago but no one got back to me so decided to create my own query. What would be great if a SF developer could actually help provide the answer? 😊
Alain CabonAlain Cabon
Hi Sonia,

You can try this new regexp:  Expression for validation of one or more emails separated by semicolon(;) 

NOT( REGEX(substitute(trim(Custom_email_list__c ),' ',''), "^([a-z0-9,!#\\$%&'\\*\\+/=\\?\\^_`\\{\\|}~-]+(\\.[a-z0-9,!#\\$%&'\\*\\+/=\\?\\^_`\\{\\|}~-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,})){1}(;[a-z0-9,!#\\$%&'\\*\\+/=\\?\\^_`\\{\\|}~-]+(\\.[a-z0-9,!#\\$%&'\\*\\+/=\\?\\^_`\\{\\|}~-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,}))*$" ))

http://​http://regexlib.com/REDetails.aspx?regexp_id=3013

A complete validation for only one email address is very complex in apex:
https://developer.salesforce.com/forums/?id=906F0000000BMjkIAG

Your expression allows also the commas and it is very difficult to validate this kind of regular expression for email (that seems to work but if it is too restrictive you will have a lot of rejects and that will be disastrous in production.

Best regards
Alain
Sonya Dhand 14Sonya Dhand 14
Amazing thankyou
Alain CabonAlain Cabon
Hello,

Your feedback about real tests of this complex regular expression would be interesting here.

The separator of the emails can be only the semicolon for this regular expression.

The separator is easy to find (there is only one semicolon in the regexp) for changing it but you have to choose only one separator ideally otherwise you could have :

email1@test.com ; email2@test.com , email3@test.com  (mix of semicolon and comma).

By the way, if a response helped you, you can choose it and close your question (best practice here).

Best regards
Alain
Sonya Dhand 14Sonya Dhand 14
Amazing- all of the above helpd :)
 
Sonya Dhand 14Sonya Dhand 14
Amazing! All of the above helped 😊 Thanks soo much
Alain CabonAlain Cabon
Ok, good news, you will be able to choose a best answer and close the question (we can earn points and badges of Salesforce, this is the game here for us helping other people to solve their problems but a best answer must be selected).
Sonya Dhand 14Sonya Dhand 14
Hi Sure, but I keep getting a 503 error. When I am able to I will. Thanks Sonya
VICKY_SFDCVICKY_SFDC
TRY THIS

 <lightning:input type="email" label="Email"
            pattern=".+@.+.com"
            placeholder="username@yourDomain.com" />
    </lightning:card>



MARK MY ANSWER AS BEST IF ITS HELP YOU