0

What I need:

  • When User Enter a mail address in text box then commas (,) should Seprate email address.

    i have used Example of jquery Autocomplete here is the url:http://jqueryui.com/autocomplete/#multiple.

  • i want that user enter multiple email address in textbox and (,) should seperate each email address.

    • here is the snapshot that i want :http://postimg.org/image/z7tv89bab/

       $(function() {
       var availableTags = [
       "[email protected]",
       "[email protected]",
      "[email protected]",
      "[email protected]",
      
       ];
      function split( val ) {
       return val.split( /,\s*/ );
       }
      function extractLast( term ) {
      return split( term ).pop();
      }
      
      $( "#tags" )
      // don't navigate away from the field on tab when selecting an item
      .bind( "keydown", function( event ) {
       if ( event.keyCode === $.ui.keyCode.TAB &&
       $( this ).data( "ui-autocomplete" ).menu.active ) {
       event.preventDefault();
      }
      })
      .autocomplete({
        minLength: 0,
        source: function( request, response ) {
        // delegate back to autocomplete, but extract the last term
         response( $.ui.autocomplete.filter(
        availableTags, extractLast( request.term ) ) );
        },
       focus: function() {
       // prevent value inserted on focus
        return false;
        },
        select: function( event, ui ) {
       var terms = split( this.value );
        // remove the current input
        terms.pop();
        // add the selected item
        terms.push( ui.item.value );
        // add placeholder to get the comma-and-space at the end
         terms.push( "" );
        this.value = terms.join( ", " );
         return false;
        }
       });
      });
      

      Tag programming languages:

5
  • 3
    You told us what you want, now show us what you tried. Commented Jun 12, 2014 at 7:20
  • YES, we're not here to do all your job. Commented Jun 12, 2014 at 7:20
  • It's the user who enter the commas ? so what do you want to do ? after submitting the form, you want mails in an array that's it ? it yes you just have to $mails = explode(',',$_POST['mails_textarea']) ; Commented Jun 12, 2014 at 7:24
  • i want that like ex [email protected](after domian name)(,) should seperate each domain name Commented Jun 12, 2014 at 7:26
  • yeah but you want it where ? After submitting (so in PHP) or Before / while editing the form (so in JS) ? Commented Jun 12, 2014 at 7:28

1 Answer 1

1

Try jquery validation plugin to validate textbox.

// Code to accept multile mails

jQuery.validator.addMethod("multiemail", function (value, element) {
    if (this.optional(element)) {
        return true;
    }

    var emails = value.split(','),
        valid = true;

    for (var i = 0, limit = emails.length; i < limit; i++) {
        value = emails[i];
        valid = valid && jQuery.validator.methods.email.call(this, value, element);
    }

    return valid;
}, "Invalid email format: please use a comma to separate multiple email addresses.");

The above function should be used in validation js

var validator = $("#frmlogin").validate({
    errorElement: 'div',
    rules: {
        email: {
            required: true,
            email: true,
            multiemail: true
        }
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.