Skip to content

Instantly share code, notes, and snippets.

@kitmenke
Created November 5, 2013 22:07
Show Gist options
  • Save kitmenke/7327188 to your computer and use it in GitHub Desktop.
Save kitmenke/7327188 to your computer and use it in GitHub Desktop.
Knockout Validation multiple email address
ko.validation.rules['multiemail'] = {
validator: function (val, validate) {
if (!validate) { return true; }
var isValid = true;
if (!ko.validation.utils.isEmptyVal(val)) {
// use the required: true property if you don't want to accept empty values
var values = val.split(';');
$(values).each(function (index) {
isValid = ko.validation.rules['email'].validator($.trim(this), validate);
return isValid; // short circuit each loop if invalid
});
}
return isValid;
},
message: 'Please enter valid email addresses (separate multiple email addresses using a semicolon).'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment