Skip to main content
Added code to trim emails
Source Link
Jaimin Sutariya
  • 11.1k
  • 5
  • 36
  • 71

You can add custom validation class like below in your js file

Validation.add('validate-comma-separated-emails', 'Please enter a valid email address.', function(emaillist) {
    emaillist = emaillist.trim();
    if(emaillist.charAt(0) == ',' || emaillist.charAt(emaillist.length - 1) == ','){ return false; }
    var emails = emaillist.split(',');
    var invalidEmails = [];
    for (i = 0; i < emails.length; i++) { 
    var v = emails[i].trim();
        if(!Validation.get('validate-email').test(v)) {
            invalidEmails.push(v);
        }
    }
    if(invalidEmails.length){ return false; }
    return true;
});

Now use validate-comma-separated-emails in your text field. Tested with magento admin panel, Output: enter image description here

You can add custom validation class like below in your js file

Validation.add('validate-comma-separated-emails', 'Please enter a valid email address.', function(emaillist) {
    if(emaillist.charAt(0) == ',' || emaillist.charAt(emaillist.length - 1) == ','){ return false; }
    var emails = emaillist.split(',');
    var invalidEmails = [];
    for (i = 0; i < emails.length; i++) { 
    var v = emails[i].trim();
        if(!Validation.get('validate-email').test(v)) {
            invalidEmails.push(v);
        }
    }
    if(invalidEmails.length){ return false; }
    return true;
});

Now use validate-comma-separated-emails in your text field. Tested with magento admin panel, Output: enter image description here

You can add custom validation class like below in your js file

Validation.add('validate-comma-separated-emails', 'Please enter a valid email address.', function(emaillist) {
    emaillist = emaillist.trim();
    if(emaillist.charAt(0) == ',' || emaillist.charAt(emaillist.length - 1) == ','){ return false; }
    var emails = emaillist.split(',');
    var invalidEmails = [];
    for (i = 0; i < emails.length; i++) { 
    var v = emails[i].trim();
        if(!Validation.get('validate-email').test(v)) {
            invalidEmails.push(v);
        }
    }
    if(invalidEmails.length){ return false; }
    return true;
});

Now use validate-comma-separated-emails in your text field. Tested with magento admin panel, Output: enter image description here

Added condition for first and last comma validation
Source Link
Jaimin Sutariya
  • 11.1k
  • 5
  • 36
  • 71

You can add custom validation class like below in your js file

Validation.add('validate-comma-separated-emails', 'Please enter a valid email address.', function(emaillist) {
    if(emaillist.charAt(0) == ',' || emaillist.charAt(emaillist.length - 1) == ','){ return false; }
    var emails = emaillist.split(',');
    var invalidEmails = [];
    for (i = 0; i < emails.length; i++) { 
    var v = emails[i].trim();
        if(!Validation.get('validate-email').test(v)) {
            invalidEmails.push(v);
        }
    }
    if(invalidEmails.length){ return false; }
    return true;
});

Now use validate-comma-separated-emails in your text field. Tested with magento admin panel, Output: enter image description here

You can add custom validation class like below in your js file

Validation.add('validate-comma-separated-emails', 'Please enter a valid email address.', function(emaillist) {
    var emails = emaillist.split(',');
    var invalidEmails = [];
    for (i = 0; i < emails.length; i++) { 
    var v = emails[i].trim();
        if(!Validation.get('validate-email').test(v)) {
            invalidEmails.push(v);
        }
    }
    if(invalidEmails.length){ return false; }
    return true;
});

Now use validate-comma-separated-emails in your text field. Tested with magento admin panel, Output: enter image description here

You can add custom validation class like below in your js file

Validation.add('validate-comma-separated-emails', 'Please enter a valid email address.', function(emaillist) {
    if(emaillist.charAt(0) == ',' || emaillist.charAt(emaillist.length - 1) == ','){ return false; }
    var emails = emaillist.split(',');
    var invalidEmails = [];
    for (i = 0; i < emails.length; i++) { 
    var v = emails[i].trim();
        if(!Validation.get('validate-email').test(v)) {
            invalidEmails.push(v);
        }
    }
    if(invalidEmails.length){ return false; }
    return true;
});

Now use validate-comma-separated-emails in your text field. Tested with magento admin panel, Output: enter image description here

Added result image
Source Link
Jaimin Sutariya
  • 11.1k
  • 5
  • 36
  • 71

You can add custom validation class like below in your js file

Validation.add('validate-comma-separated-emails', 'Please enter a valid email address.', function(emaillist) {
    var emails = emaillist.split(',');
    var invalidEmails = [];
    for (i = 0; i < emails.length; i++) { 
    var v = emails[i].trim();
        if(!Validation.get('validate-email').test(v)) {
            invalidEmails.push(v);
        }
    }
    if(invalidEmails.length){ return false; }
    return true;
});

Now use validate-comma-separated-emails in your text field. Tested with magento admin panel, Output: enter image description here

You can add custom validation class like below in your js file

Validation.add('validate-comma-separated-emails', 'Please enter a valid email address.', function(emaillist) {
    var emails = emaillist.split(',');
    var invalidEmails = [];
    for (i = 0; i < emails.length; i++) { 
    var v = emails[i].trim();
        if(!Validation.get('validate-email').test(v)) {
            invalidEmails.push(v);
        }
    }
    if(invalidEmails.length){ return false; }
    return true;
});

Now use validate-comma-separated-emails in your text field.

You can add custom validation class like below in your js file

Validation.add('validate-comma-separated-emails', 'Please enter a valid email address.', function(emaillist) {
    var emails = emaillist.split(',');
    var invalidEmails = [];
    for (i = 0; i < emails.length; i++) { 
    var v = emails[i].trim();
        if(!Validation.get('validate-email').test(v)) {
            invalidEmails.push(v);
        }
    }
    if(invalidEmails.length){ return false; }
    return true;
});

Now use validate-comma-separated-emails in your text field. Tested with magento admin panel, Output: enter image description here

Source Link
Jaimin Sutariya
  • 11.1k
  • 5
  • 36
  • 71
Loading