Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Custom message for Validation of email field on marketing page

(0) ShareShare
ReportReport
Posted on by 20

Hello,

as the out of the box validation of an email form field is only checking if an '@' is in the String, i needed to code a custom validation.

here is the working validation:

<script language="javascript" type="text/javascript">
    MsCrmMkt.MsCrmFormLoader.on('formSubmit', function (event) {

    var emailfield = document.getElementById('guid').value;

    var email = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9_.-]+\.[a-zA-Z]{2,}$/ ;

    if(email.test(emailfield) == false ){

        // display error message

        event.preventDefault();
        
    };
   
}
    );
</script>

Now i want to access and show the user the error when entering an email that does not match the regular expression, the same way it its displayed out of the box.

pastedimage1626077061228v1.png

Is it possible to access it through the form loader? The requirements state to not use an alert as it is bad practice.

Thank you in advance. 

Greetings Jakob

  • jakobb Profile Picture
    jakobb 20 on at
    RE: Custom message for Validation of email field on marketing page

    Thank you very much.

    With your help it worked :)

  • Verified answer
    Nya Profile Picture
    Nya 29,058 on at
    RE: Custom message for Validation of email field on marketing page

    Hi Jakob,

    Please refer to the following article.

    Native form validation with JavaScript | falldowngoboone 

    The validation message is not a message come with Dynamics.

    You can check out its Attributes from here.

    <form> - HTML: HyperText Markup Language | MDN (mozilla.org)

    To customize it, please refer to:

    javascript - How to change default “please include an @ in the email address”? - Stack Overflow

    If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.

    Best Regards,

    Nya

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans