Created
June 22, 2013 13:28
-
-
Save zerc/5840864 to your computer and use it in GitHub Desktop.
Some addition validators for Backbone.Form
This file contains 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
(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