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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Conditional Validation Error Message in Marketing Form

(0) ShareShare
ReportReport
Posted on by

We have a single line text field called “Phone Number” that is not required on form submission, but whose value needs to be validated to contain 10 digits to be considered a valid number.

 

I am trying to replicate Dynamics validation popup message:

 pastedimage1622735685180v1.png

I would like to add the “This field is required” popover to Phone number field once it contains data is invalid.

 

I noticed that on submit of the form, the following HTML element is added to the <form> element:

 

<div id="validation-summary">

<p id="error_7f685ebb-7c54-4cff-a1bc-772562d25c38" role="alert" hidden="">E-mail*: This field is required</p>

</div>

 

 

I thought that I could simply add another p tag with a similar id, but the actual id coming from the Phone number field like so:

 

<p id="error_ac6a065d-364e-40d6-9a19-d9bf1ed4aa3e" role="alert" hidden="">Phone Number*: This field is required</p>

 

 

For more context, here’s the actual Phone number field HTML: (notice that I matched the input’s id to the validation p tag id above)

 

<div class="lp-form-field" data-required-field="false">

   <label class="lp-ellipsis" for="ac6a065d-364e-40d6-9a19-d9bf1ed4aa3e" title="">Phone number</label>

   <input class="lp-form-fieldInput phone-number-validation" id="ac6a065d-364e-40d6-9a19-d9bf1ed4aa3e" name="ac6a065d-364e-40d6-9a19-d9bf1ed4aa3e" style="width: 100%; box-sizing: border-box;" title="" type="tel" inputmode="text">

</div>

 

I’m guessing that the div#validation-summary is returned from the server side and there’s no way for me to hack the HTML to get this validation behavior for my other fields that have conditional validation requirements.

 

Here’s my custom validation code that I attach in the Marketing Form raw HTML after the ending </form> tag:

 

<script defer>

    MsCrmMkt.MsCrmFormLoader.on('formSubmit', function(event) {

        if (!jQuery(".phone-number-validation").inputmask("isComplete")) {

            event.preventDefault();

        }

        event.setFormNotification(function (n) {

            console.log(n);

        });

    });

</script>

 

I can prevent the submission and show an alert, but it’s not visually appealing. I’d like to replicate what Microsoft has in place.

 

I tried reading documentation, but it’s very minimal:

https://docs.microsoft.com/en-us/dynamics365/marketing/developer/marketing-form-client-side-extensibility

 

This question is close to what I’m trying to achieve, but I notice it’s adding a custom error message. If this is what I have to do, that’s fine, but I’m trying to use the same UI/UX Microsoft has in place.

https://community.dynamics.com/365/marketing/f/dynamics-365-for-marketing-forum/411731/error-message-in-marketing-form

 

Here’s another great post about how to achieve this, but it looks like Dynamics would block us from trying to replicate its validation UI:

https://community.dynamics.com/365/marketing/f/dynamics-365-for-marketing-forum/395996/adding-fields-validation-using-javascript-to-marketing-form-in-dynamics-365/1069081#1069081

Thank you!

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

    Hi Tony,

    Here is an issue about Email Validation, which is similar to your issue.

    (+) Email Validation on Landing Page - Dynamics 365 Marketing Forum Community Forum

     

    You can try to make an alert when the Phone number is not valid refer to the above post.

     

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 156

#2
ManoVerse Profile Picture

ManoVerse 153 Super User 2026 Season 1

#3
Zhilan Profile Picture

Zhilan 49

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans