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 :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Portal Webform - word count validation

(0) ShareShare
ReportReport
Posted on by 30

Hi,

I need to add wordcount validation for specific fields  in Opportunity entity on an advanced web form. Does anybody know how to do this?

It needs to display a customisable alert and work for both typed and pasted words on clicking continue to next web form step.

Help!!

James 

I have the same question (0)
  • Verified answer
    Inogic Profile Picture
    682 on at

    We can use java script to achieve wordcount validation for specific field on Opportunity Advanced Form.

    • Step 1 : Add below code to the Advanced Form Step form under Form options tab. And save it.3644.jpg

    $(document).ready(function () {

    //Create word count validator

    var wordCountValidator = document.createElement('span');

    //setup validator property and associated field

    wordCountValidator.style.display = "none";

    wordCountValidator.id = "new_wordcount_Validator";

    wordCountValidator.controltovalidate = "name";  // single of text

    wordCountValidator.evaluationfunction = function () {

         var wordCount= $("#name").val();

         var countWords = (wordCount.split(" ")).length;

       if (wordCount!== null && wordCount!== "" && wordCount!== undefined) { // Check condition

           if (countWords > 2) {  // check sub condition

    //setup custom validation message

                   this.errormessage = "<a href='#new_wordcount_label'>Topic should be of two words.</a>";

               return false;

           }

           else {

               return true;

           }

       }

       else {

           return true;

       }

    };

    // Add the validator to the page validators array:

    Page_Validators.push(wordCountValidator);

    });

    • Step 2 : Clear portal cache and view the result.

     If entered topic value is more the two then it will show the error message0027.jpg

    • Step 3 : If entered topic value is two or less than two it will save the form.40513.jpg

    • After clicking on submit button it will save form7065.jpg

    • It works for both typed and pasted words.

    Hope this helps!!!

    If you find this solution helpful, please mark it as verified.

  • Jim Tredree Profile Picture
    30 on at

    Thank you very much! That is very helpful. Literal gold star moment

  • Inogic Profile Picture
    682 on at

    Hi Jim,

    Glad to know our solution worked for you. If you dont mind, can you please mark my answer as verified so that if someone else also face similar issue in future, they can try the same since they would prefer the solution if its a verified one.

    Thanks,

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 > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 80

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans