1

I have a RegEx created and tested in regex platforms, this one:

;.+$

If I check its functionality the result is okay, you could check it too in this link https://regex101.com/r/ocDofm/1/.

The problem is that, when I implement it into a Validation Rule for a Specific field, it does not work. My Validation Rule is :

REGEX( Email__c, ';.+$')

And, if I put the same text that I use on regex101.com web, the Validation Rule does not run. For example, if I open Email__c field, which is a Long Text Area field, and I put this text;

[email protected];[email protected];and so on...

Validation Rule should work and error message should appear, but it happens nothing.

Any idea? Thanks.

EDIT: There is an example of the text that I want to be possible in the Email__c field:

[email protected];
[email protected];
[email protected];

So, the next text, should fire the Validation Rule:

[email protected];a
[email protected];
[email protected];
2
  • 1
    What exactly do you expect the validation rule to allow and disallow?
    – Phil W
    Commented Mar 1, 2021 at 10:05
  • It must avoid that user put so many emails inline. So, the rule is that user must put emails ending with ';' and with line breaks, he cannot put characters after the ';' character in the same line.
    – CPS
    Commented Mar 1, 2021 at 10:13

1 Answer 1

6

That's because SFDC matches the whole field against your REGEX, your whole Email__c is not only ';.+$', plus $ is a special character, so you need something like this

REGEX( Email__c, '.*[;.+$].*')

If you're only interested in ; character then put it like this '.*;.*'

Another point is that if you are only curious about ; character you can use CONTAINS(Email__c, ';')

UPDATE:

Try this one .*;[^\n].*, this should only trigger when you don't have new line after ;

UPDATE2:

REGEX( Email__c, '((.||(\r?\n))*;.((\r?\n)||$)(.||(\r?\n))*)')

15
  • I appreciate your help, and it's useful understand more about regex and validationrules, but still not working...
    – CPS
    Commented Mar 1, 2021 at 10:26
  • Emails must end with ";" character, and be listed with line breaks. Example: [email protected];(line break) [email protected];(line break) [email protected];
    – CPS
    Commented Mar 1, 2021 at 10:29
  • so if you have line break it's ok, if you don't have line break it's an error?
    – ytiq
    Commented Mar 1, 2021 at 10:32
  • I just tested without line breaks and my Regex works, I'll update it for line breaks right now
    – ytiq
    Commented Mar 1, 2021 at 10:33
  • Sorry, I put the example on my question text, because here in this comments I could not put properly.
    – CPS
    Commented Mar 1, 2021 at 10:33

You must log in to answer this question.

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