Email Address Double Check

Hi,

We’re having an issue with our customers correctly typing their email address. I’ve added a second email address field and would like to have it display some error text if it doesn’t match, and make it mandatory that it matched before moving on.

I can do this in the front end, but it would require at least a composite and custom settings on the next button for every page that had those fields - I’m fairly sure this could be done fairly easy with JavaScript and I was wondering if anyone had already done it?

Thanks,

Vicky

Morning Victoria,

Create a fragment presenter in code studio along with a reference to your normal email address field as follows and make the verify email field mandatory.

/**

 * Fragment Validator

 * Used within Pagebuilder to validate fields

 */

return {

    /**

     * @param {fragment_presenter} Fragment instance

     */

    main: function(fragment_presenter) {

        email_field = cs.ref("User_Email_Address");

        email_value = fragment_presenter.get_values()[email_field];

        verify_value = fragment_presenter.get_value();

        if (email_value == verify_value) {return true} else {return "Email address does not match"}

    }

}

The fragment validator is then applied at the bottom of the settings area for the mandatory verify field.

Please let me know if you have any further questions.

Hi,

Thanks for replying, this looks good but I’m getting ‘invalid format’ on my second email address field? either with a data type of email address or text single line.

Thanks

Morning Victoria,

Apologies, it’s possible you are on a version which doesn’t support the new boilerplate.

Reduce your fragment validator to just:

email_field = cs.ref("User_Email_Address");

email_value = fragment_presenter.get_values()[email_field];

verify_value = fragment_presenter.get_value();

if (email_value == verify_value) {return true} else {return "Email address does not match"}

Let me know if you have any further issues.

That’s working perfectly, thank you

2 Likes

Great to hear, thank you Victoria.