SOLVED

Formatting Email Fields in Forms 2.0

Go to solution
Highlighted
Anonymous
Not applicable

Formatting Email Fields in Forms 2.0

In forms 2.0, I'm looking for a way to make sure people enter a properly formatted email address. Right now someone can type in name@domain and it will still accept the email. I'd like to ensure that a .com (or .net .org etc.) has to be added to the email in order to accept it.

Any help would be apperciated.
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Anonymous
Not applicable

Re: Formatting Email Fields in Forms 2.0

Hi Abel, Let me explain in simpler way: When you are on step no 2 : FIELD DETAILS, inproperties, under field type define email address. It wont accept invalid email address. Hope this is helpful. Thank you Regards Sonia

View solution in original post

9 REPLIES 9
Highlighted
Anonymous
Not applicable

Re: Formatting Email Fields in Forms 2.0

Hi Abel, Let me explain in simpler way: When you are on step no 2 : FIELD DETAILS, inproperties, under field type define email address. It wont accept invalid email address. Hope this is helpful. Thank you Regards Sonia

View solution in original post

Highlighted
Anonymous
Not applicable

Re: Formatting Email Fields in Forms 2.0

Ah, yes. That makes sense. Thank you!
Highlighted
Anonymous
Not applicable

Re: Formatting Email Fields in Forms 2.0

Hi Sonia,

I treid as you defined it but it is accepting email address like 'me@gmail', it is not fully validating the email address.

Highlighted

Re: Formatting Email Fields in Forms 2.0

Has anyone found a resolution for this? i get a lot of errors in my integration and am not able to send to these emails if they do not have a .com, .org, .net. etc...

This drives deliverability down and invalids up.

Highlighted
Level 10 - Community Moderator

Re: Formatting Email Fields in Forms 2.0

It's simple to do rough public address validation for domains with at least two parts:

MktoForms2.whenReady(function(form) {

  form.onValidate(function(nativeValid) {

    if (!nativeValid) return;

    var emailField = 'Email',

      emailValue = form.getValues()[emailField],

      emailInvalidError = 'Please enter a probably-valid email address';

    if (/^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)+$/.test(emailValue)) {

      form.submittable(true);

    } else {

      form.showErrorMessage(emailInvalidError, form.getFormElem().find('#' + emailField));

    }

  });

});

But bear in mind that no regular expression, no matter how long and complex it appears, can really account for the email addresses that are accepted in the real world (and only those addresses).  For example, the above regex will block carrie@au but allow carrie@com.au, even though neither are truly publicly sendable (in this case, because a reserved second-level domain under a ccTLD like .au functions more like a top-level domain, even if it has two parts).

Highlighted

Re: Formatting Email Fields in Forms 2.0

Thank you Sanford! you are always such a huge help

Highlighted
Level 1

Re: Formatting Email Fields in Forms 2.0

Hi Sanford! I work with Carrie Lawson and am trying to make your script work. Is it as simple as putting in a JS tag on the template? That's what I did, but it's not working: http://info.viewpoint.com/Regex-Email-Validation-Test.html
(I was able to submit with carrie@au)

Is there something simple I'm missing?

If not, I'll try to enlist our IT team to help out here, but was hoping to quickly implement what you were so kind to help us out with. 😉

Highlighted
Level 10 - Community Moderator

Re: Formatting Email Fields in Forms 2.0

Out at our MUG meetup, but I'll check later!

Highlighted
Level 10 - Community Moderator

Re: Formatting Email Fields in Forms 2.0

If you look in the browser console, you'll see the culprit:

pastedImage_0.png

You're trying to load the validation code before the MktoForms2 library (forms2.js) is available. That won't work, since the code needs to hook MktoForms2.whenReady().

If this is a Free-Form Landing Page, make sure the HTML element that includes the form script is below the Form element on the right side of the LP editor.