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

Form validation: email input type and the multiple attribute #7424

Open
RobJohnston opened this issue Feb 29, 2016 · 3 comments
Open

Form validation: email input type and the multiple attribute #7424

RobJohnston opened this issue Feb 29, 2016 · 3 comments

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 form validation example, more than one e-mail address will not validate.

I do have a work-around, but it involves changing the input type from "email" to "text". Any thoughts on this? Is there a better way?

<div class="wb-frmvld">
    <form action="#" method="get" id="validation-example">
        ...
        <div class="form-group">
            <label for="email1"><span class="field-name">Email address</span> (yourname@domain.com)</label>
            <input class="form-control multiemail" id="email1" name="email1" type="text" />
        </div>
...
    <script type="text/javascript">
        wb.doc.on("wb-ready.wb", function (event) {
          jQuery.validator.addMethod("multiemail", function (value, element) {
                    if (this.optional(element)) {
                        return true;
                    }
                    var emails = value.split(','),
                        valid = true;
                    for (var i in emails) {
                        value = emails[i];
                        valid = valid && jQuery.validator.methods.email.call(this, value, element);
                    }
                    return valid;
                }, jQuery.validator.messages.email);
        });
    </script>
@LaurentGoderre
Copy link
Member

Maybe post an issue to jQuery Validation?

@RobJohnston
Copy link
Contributor Author

I considered that, but jQuery Validation doesn't use the type="email" either, not even for a single e-mail address, so I assumed it was a WET thing. See http://jqueryvalidation.org/email-method/

Ideally, would just want to enter this:

<input class="form-control" id="email1" name="email1" type="email" multiple />

@RobJohnston
Copy link
Contributor Author

Let's slap an "upstream" label on this. See jquery-validation/jquery-validation#1722. I don't know when I'll get to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants