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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Form validation with j...
Power Pages
Unanswered

Form validation with jQuery validation plugin

(0) ShareShare
ReportReport
Posted on by 133

Hi,

I would like to add jQuery validation plugin to validate fields in a webform step on entry.

1. Where to add? (header, webpage, webform step)

2. Where to add rules for a validation (webform step, webpage)

Thank you in advance.

 

Categories:
I have the same question (0)
  • oliver.rodrigues Profile Picture
    9,453 Most Valuable Professional on at

    Hi, the ideal place for you to add the validation will be Web Form Steps

     

    You can also use Web Page but I wouldn't really recommend, I try normally to keep the JS code specific to the main component

     

    for more info: https://docs.microsoft.com/en-us/powerapps/maker/portals/configure/add-custom-javascript

     

  • natalya Profile Picture
    133 on at

    Thank you for the answer.

    So to initializes jQuery validation plugin I have to add the following code to Web Form step?

    pic1.PNG

    is it correct?

    Thank you

  • oliver.rodrigues Profile Picture
    9,453 Most Valuable Professional on at

    Hi, no you don't need to worry about initializing jQuery plugin

    jQuery will be loaded automatically with your Portals, you can just add the validation code:

    if (window.jQuery) {
     (function ($) {
     $(document).ready(function () {
     if (typeof (Page_Validators) == 'undefined') return;
     // Create new validator
     var newValidator = document.createElement('span');
     newValidator.style.display = "none";
     newValidator.id = "emailaddress1Validator";
     newValidator.controltovalidate = "emailaddress1";
     newValidator.errormessage = "<a href='#emailaddress1_label'>Email is a required field.</a>";
     newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
     newValidator.initialvalue = "";
     newValidator.evaluationfunction = function () {
     var contactMethod = $("#preferredcontactmethodcode").val();
     if (contactMethod != 2) return true; // check if contact method is not 'Email'.
     // only require email address if preferred contact method is email.
     var value = $("#emailaddress1").val();
     if (value == null || value == "") {
     return false;
     } else {
     return true;
     }
     };
     
     // Add the new validator to the page validators array:
     Page_Validators.push(newValidator);
     
     // Wire-up the click event handler of the validation summary link
     $("a[href='#emailaddress1_label']").on("click", function () { scrollToAndFocus('emailaddress1_label','emailaddress1'); });
     });
     }(window.jQuery));
    }

    I think probably the first part I normally ignore "if (window.jQuery)...".. but that shouldn't be any problem either

  • natalya Profile Picture
    133 on at

    Thank you. I am looking for a validation on an entry, not on a submit.

    If it is "First Name" filed, rules for entry: no less then 2 letters, no symbols

    and if user enters 3d letter or symbol, error shows up under field right away.

     

  • oliver.rodrigues Profile Picture
    9,453 Most Valuable Professional on at

    have you considered adding mask?: http://oliverrodrigues365.com/2020/04/15/power-apps-portals-adding-field-mask/

     

    another option would be validation the content on the On Change event, and displaying an error message or something for the user to correct the data, you will still need the same validation on the form submit, so I still think you can consider the form validation

  • natalya Profile Picture
    133 on at

    Thank you, Oliver. 

    Adding a mask is great idea! I will try this as well.

    Ans found a solution how to use JQuery validation plugin.

    I added some libraries, did some customization.

    Thank you again.

    PS:

    Congratulation on your MVP

  • oliver.rodrigues Profile Picture
    9,453 Most Valuable Professional on at

    super 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
rezarizvii Profile Picture

rezarizvii 53

#2
DP_Prabh Profile Picture

DP_Prabh 40

#3
oliver.rodrigues Profile Picture

oliver.rodrigues 28 Most Valuable Professional

Last 30 days Overall leaderboard