Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some addition validators for Backbone.Form
(function (Form) {
Form.validators.errMessages = {
youtube: 'Enter link from YouTube',
positive_int: 'Enter positive integer'
};
Form.validators.youtube = function(options) {
options = _.extend({
type: 'youtube',
message: this.errMessages.youtube,
regexp: /^(http|https):\/\/(www\.youtube\.com|youtu.be)\/[a-zA-Z0-9\?&\/=\-]+$/gmi
}, options);
return Form.validators.regexp(options);
};
Form.validators.positive_int = function(options) {
options = _.extend({
type: 'positive_int',
message: this.errMessages.positive_int
}, options);
return function positive_int(value) {
options.value = value;
var err = {
type: options.type,
message: options.message
};
if (value === null || value === undefined || value === false || value === '' || value <= 0) return err;
};
};
}(Backbone.Form));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.