cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

webform javascript validation

Hi!

I'm trying to validate a field in my webform step where it checks if the email ends with the domain of their website, but whatever i try it doesn't work.
Here's my code:

 

if (window.jQuery) {
   (function ($) {
      if (typeof (webFormClientValidate) != 'undefined') {
         var originalValidationFunction = webFormClientValidate;
         if (originalValidationFunction && typeof (originalValidationFunction) == "function") {
            webFormClientValidate = function() {
               originalValidationFunction.apply(this, arguments);
                var email = $("#cr36b_epasts.text").val();
                var domain = $("#cr36b_domeins.text").val();
                if (email.endsWith(domain)) {
                    return true;
                } else {
                    return false;
                    alert("email has to end with your domain.");
                }
            };
         }
      }
   }(window.jQuery));
}

 

I've inserted this js in Webform->webform step->form options->custom js. Would appreciate help with this, even if it is some other way of validation that isnt JS.
I would also like to validate the domain input field to make sure that it isnt any generic email websites such as gmail, yahoo, Hotmail etc.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Solution Supplier
Solution Supplier

Re: webform javascript validation

Hi @KD203,

These kinds of bugs seem to occur too often. Looks like the product is not providing the right files currently - webFormClientValidate isn't an available function, but entityFormClientValidate is. Unfortunately, entityFormClientValidate isn't called, so.. we need to make our own webFormClientValidate function. Note that the "alert" function should come before your return statement.

if (window.jQuery) {
   (function ($) {
        webFormClientValidate = function() {
            var email = $("#cr36b_epasts.text").val();
            var domain = $("#cr36b_domeins.text").val();
            if (email.endsWith(domain)) {
                return true;
            } else {
                alert("email has to end with your domain.");
                return false;
            }
        };
   }(window.jQuery));
}

 

View solution in original post

2 REPLIES 2
Highlighted
Solution Supplier
Solution Supplier

Re: webform javascript validation

Hi @KD203,

These kinds of bugs seem to occur too often. Looks like the product is not providing the right files currently - webFormClientValidate isn't an available function, but entityFormClientValidate is. Unfortunately, entityFormClientValidate isn't called, so.. we need to make our own webFormClientValidate function. Note that the "alert" function should come before your return statement.

if (window.jQuery) {
   (function ($) {
        webFormClientValidate = function() {
            var email = $("#cr36b_epasts.text").val();
            var domain = $("#cr36b_domeins.text").val();
            if (email.endsWith(domain)) {
                return true;
            } else {
                alert("email has to end with your domain.");
                return false;
            }
        };
   }(window.jQuery));
}

 

View solution in original post

Highlighted
Helper II
Helper II

Re: webform javascript validation

Worked perfectly, thank you!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Users online (6,258)