Formatting Email Fields in Forms 2.0 | Community
Skip to main content
February 7, 2014
Solved

Formatting Email Fields in Forms 2.0

  • February 7, 2014
  • 3 replies
  • 4312 views
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.
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by
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

3 replies

July 21, 2014

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.

Carrie_Lawson
New Participant
August 11, 2016

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.

SanfordWhiteman
New Participant
August 11, 2016

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).

February 7, 2014
Ah, yes. That makes sense. Thank you!
Accepted solution
February 7, 2014
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