web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
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

I have the same question (0)
  • Verified answer
    Nya Profile Picture
    29,060 on at

    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

  • jakobb Profile Picture
    20 on at

    Thank you very much.

    With your help it worked :)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans