Created
June 22, 2013 13:28
Revisions
-
zerc created this gist
Jun 22, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ (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));