Contains on Comma separated value in validation Rule

formulavalidation-rule

I have Validation Rule that checks if entered Email ID has particular Domain.

If it does not contain any of these domains then validation should fire

I am storing Domains in a Hierarchy Custom setting like

Domain__c = @abc.com,@test.com,@test123.com

And then in the validation rule doing the following:

NOT(CONTAINS(Email_ID__c, $Setup.Hierarchy_Setting__c.Domain__c))

Its working only when Domain__c has single value(Domain__c = @abc.com), but not working with comma separated values.

I tried using colon like Domain__c = @abc.com:@test.com:@test123.com but no luck.

I also tried with custom labels.

Any other approach?

Best Answer

You could try flipping your logic to see if the custom setting contains the domain in the email.

Below, I'm looking in the custom setting for the domain (using LEN and RIGHT to strip out the domain).

NOT(Contains($Setup.Hierarchy_Setting__c.Domain__c, RIGHT(Email_ID__c, LEN(Email_ID__c) - FIND('@', Email_ID__c))

(Note: not tested, so you might need to adjust the logic for getting the domain part of the email address)

Related Topic