Skip to main content

Notifications

Announcements

No record found.

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 

  • Inogic Profile Picture
    Inogic 402 on at
    RE: Portal Webform - word count validation

    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,

  • Jim Tredree Profile Picture
    Jim Tredree 30 on at
    RE: Portal Webform - word count validation

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

  • Verified answer
    Inogic Profile Picture
    Inogic 402 on at
    RE: Portal Webform - word count validation

    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.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans