required validator

thedersen edited this page Dec 26, 2011 · 3 revisions
var SomeModel = Backbone.Model.extend({
  validation: {
    name: {
	  required: true | false
	}
  }
});

var SomeModel = Backbone.Model.extend({
  validation: {
    name: {
	  required: function() {
		return true | false;
	  }
	}
  }
});
  • empty string is invalid
  • non-empty string is valid
  • string with just spaces is invalid
  • null is invalid
  • undefined is invalid
  • false boolean is valid
  • true boolean is valid
  • required can be specified as a method returning true or false