Forced Field Validation

@Ronald_Tu, A quick check… in your Chrome do you see the error “lp is not defined?”

@xavier.bussonnais - Where would find that error? I don’t see anything like that on my browser window. Could you screenshot where the error “Ip is not defined” would show up?



In Chrome, right click on your page and click on Inspect (CTRL+SHIFT+I on PC). It will open a panel at the bottom or the right of your Chrome browser. Then select the Tab Console and reload the page. If there is something wrong in your JS the error will show there.



1 Like

The page URL is shared at the top of the thread. It looks like he ran into the same problem you had.

@xavier.bussonnais could you share the script you edited to get it working?

Sure. Here it is

    window.ub.form.customValidators.checkDobFormat = {
        isValid: function(value) {
          return /(((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-9]|1[0-2])\/((19|20)\d\d))$/.test(value);

        message: 'Enter date in dd/mm/yyyy format ONLY.',

      window.ub.form.validationRules.date_of_birth.checkDobFormat = true;

It uses the core methods of the ub object (customValidators).

1 Like

Hey @xavier.bussonnais, this seem to have worked. But Now I am running into another error, when I put in the proper date format in, it is firing off the error message.

Well, this is because of the date format. The following regular expression is validating dd/mm/yyyy date format:
return /(((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-9]|1[0-2])\/((19|20)\d\d))$/.test(value);

To obtain a MM/DD/YYYY, you must change the regular expression to:
return /((0[1-9]|1[0-2])\/((0|1)[0-9]|2[0-9]|3[0-1])\/((19|20)\d\d))$/.test(value);

As well, make sure you change your error message to :
"Enter date in mm/dd/yyyy format ONLY."

1 Like

Hi! I am trying to use this script to validate date of birth in my form as (MM/DD/YYYY) and can’t get it to work. The validation error won’t show up when I’ve tested it out using the incorrect formatting.

Below are screenshots of the scripts I’ve placed on the landing page, as well as my form setup.

Screen Shot 2020-05-21 at 11.56.33 AM|690x141

Screen Shot 2020-05-21 at 12.06.22 PM|690x425

Hi @lasuma12,

This is probably because the jQuery script is being loaded after your validation script.


Hi! Thank you for your response! I moved the jQuery script to the Head of the page and republished. When I tested, the verification for age still didn’t show an error when I typed it it incorrectly.

Should the Form Field type be a Single-Line Text or something else? I’ve followed all of the steps above as far as I can tell. Not sure why this isn’t working. Is there any other solution for this?

Could you include the URL to the page so we can inspect?

It might be helpful to see what is going on within the page.