Adding custom validation to form fields



Show first post

112 replies

Hi all,

We can’t seem to implement the email validation script on our popups (it works fine on our landing pages, though). I’ve set the script in Script Manager to “Included on All”, which didn’t produce results, and then went into one of the popups and added it manually through the Javascripts feature, again, to no avail.

Any advice?

Userlevel 5

Hey @ArtZ could you include a URL to a page you have this script and popup on?

I can inspect it to confirm the implementation. I just tested in a popup myself and it works. So there may jut be a typo.

Hi Kyle,

Thanks for getting back to me!

Here’s the page - https://miappi.com/. The popup I’m referring to is the one you get after clicking the “Find Out More” CTA in the header. It’s supposed to be filtering out private email domains, but it’s not.

Same as in case of the landing pages, the popups’ form’s email field is set to id: email and I’m using this script before body end tag:

script>
window.ub.form.validationRules.email.nonGmail = true;
/script>

<script>
  window.ub.form.customValidators.nonGmail = {
    isValid: function(value) {
      return /\@(?!(me|mac|icloud|gmail|googlemail|hotmail|live|msn|outlook|yahoo|ymail|aol)\.)/.test(value.toLowerCase());
    },

message: 'Please enter your work email address',
  };
</script>
Userlevel 5

@ArtZ The script isn’t there. Are you sure you published the popup with the script in the popup?

Yup, I’m positive. Here’s the screenshot (added to this popup, then saved and published):

Userlevel 5

@ArtZ Does the script work in “preview” mode in the Unbounce builder?

Hi Kyle. Yup, surprisingly it does work in the preview mode.

Userlevel 5

@ArtZ Well in that case, I have no idea what’s going on haha!
Sounds like a good case for the Unbounce support team.

The digit validation doesn’t seem to be working 😕

Digits only isn’t working. Any help?

I only have a very basic knowledge of javascript. How can I get this script to validate a radio button? (If ‘No’ option is checked, an alert message appears)

Bumping this.

Would really like to know how to show a custom alert if a specific radio button is checked!

Reply