Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

email input type and the multiple attribute #1722

Closed
RobJohnston opened this issue Feb 29, 2016 · 5 comments · May be fixed by #2074
Closed

email input type and the multiple attribute #1722

RobJohnston opened this issue Feb 29, 2016 · 5 comments · May be fixed by #2074
Labels

Comments

@RobJohnston
Copy link
Contributor

HTML5 has a multiple attribute that can be specified for e-mail addresses as well as files. For e-mail, it would be a set of comma-separated strings, each of which is a valid email address.

When applying the multiple attribute to the existing jQuery Validation Plugin Demo, more than one e-mail address will not validate.

There are solutions to this (e.g., http://stackoverflow.com/questions/10352221/jquery-validation-plugin-multiple-email-addresses), but ideally, one should be able to write the following without using addMethod:

<input id="email1" name="email1" type="email" multiple>
@staabm
Copy link
Member

staabm commented Feb 29, 2016

This seem to be pretty new, never seen it in the wild yet.

PR with a patch and unit test welcome.

@Sven-Mad
Copy link

Sven-Mad commented Jul 11, 2017

hi @ll

here my solution, for multiple-emails

$.validator.methods.email = function(value, element, no_multiple) {
  if (this.optional(element)) {
    return true;
  }
  if (!element.multiple || !no_multiple) {
    return /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.test(
      value
    );
  } else {
    var emails = value.split(/[,]+/); // split element by ,
    valid = true;
    for (var i in emails) {
      value = emails[i];
      valid =
        valid &&
        $.validator.methods.email.call(this, $.trim(value), element, false);
    }
    return valid;
  }
};

i hope it helps

@RobJohnston
Copy link
Contributor Author

RobJohnston commented Jul 11, 2017

See also: https://stackoverflow.com/questions/10352221/jquery-validation-plugin-multiple-email-addresses#10352428, so it has existed in the wild for over 5 years now.

@Sven-Mad
Copy link

My function is for the HTML5 element input-type = "email" with and without the attribute multiple
<input id="email1" name="email1" type="email" multiple>

It verifies by itself whether it is multiple and then makes the right test

@stale
Copy link

stale bot commented Jun 5, 2018

This issue/proposal has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and one of the maintainers will (try!) to follow up.
Thank you for contributing :)

@stale stale bot added the stale Used to mark stale issues label Jun 5, 2018
@stale stale bot closed this as completed Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants