Created
November 5, 2013 22:07
-
-
Save kitmenke/7327188 to your computer and use it in GitHub Desktop.
Knockout Validation multiple email address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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