The emailRegexValidator and the urlRegexValidator settings

Last updated Thursday, June 15, 2017 in Email Experience Manager for Developer
Keywords: Configuration

To validate a contact's email address and any URLs that a contact clicks in an email message, the Email Experience Manager (EXM) uses the following two settings:

  • emailRegexValidator – used to verify that a string is in valid email format, for example, when EXM validates an email address during a dispatch.

    Note

    If you use Sitecore Email Cloud, the email delivery service also validates the email addresses during the dispatch of an email campaign. Therefore, there is a risk that Sitecore Email Cloud validates an email address but EXM does not, or the other way around.

  • urlRegexValidator – used to check if a string is a valid URL when a contact clicks a link in an email message.

Both settings can use any regular expression for validation as a value. You can replace the default value with your custom regex. To keep a record of the initial value, you can modify the settings by commenting out the default value or overriding the configuration file.

You can define the settings in the \App_Config\Include\EmailExperience\Sitecore.EmailExperience.Core.config file in the <sitecore>/<settings> section:

  • The emailRegexValidator setting:
    <!-- EXM EMAIL REGEX VALIDATOR
            Regex validation for emails
    -->
    <emailRegexValidator type="Sitecore.Modules.EmailCampaign.Validators.RegexValidator, Sitecore.EmailCampaign" singleInstance="true">
        <param desc="regexValue" ref="settings/setting[@name='EXM.EmailValidationRegex']/@value" />
    </emailRegexValidator>

You can define the regular expression in the following setting:

<!-- The regular expression used for e-mail validation. -->
<setting name="EXM.EmailValidationRegex" value="^[\p{L}0-9\+\-_\!\$\%\&amp;\*\?]+(?:\.[\p{L}0-9\+\-_\'\!\$\%\&amp;\*\?]+)*@(([\p{L}0-9\-]+(?:\.[\p{L}0-9]+)+)|(\[\d{1,3}(\.\d{1,3}){3}\]))$" />
  • The urlRegexValidator setting:
    <!-- EXM URL REGEX VALIDATOR
            Regex validation for URLs
    -->
    <urlRegexValidator type="Sitecore.Modules.EmailCampaign.Validators.RegexValidator, Sitecore.EmailCampaign" singleInstance="true">
        <param desc="regexValue" ref="settings/setting[@name='EXM.UrlValidationRegex']/@value" />
    </urlRegexValidator>

You can define the regular expression in the following setting:

<!-- The regular expression used for url validation. -->
<setting name="EXM.UrlValidationRegex" value="^(http|https){1}\:\/\/(([a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]?)\.)*([a-zA-Z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9]?)(:\d{2,5})?(\/[a-zA-Z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9]?)*(\/{1})?$" />

Note

The default regex is not RFC compliant and does not cater for all cases. To address specific regional use cases or business needs, you must use a custom regular expression.

Send feedback about the documentation to docsite@sitecore.net.