Since this tutorial hasn't treated database access yet, we will do a simpler example, but hopefully you will see that you can do just about everything with the Custom Validator.The control allows you to validate both clientside and serverside, where the serverside approach is probably the most powerful. Value, which is the string of the control being validated, for it's length.

page validate not validating custom validators-1page validate not validating custom validators-56

When the model is validated all associated views with attributes from that model will validate its related elements.

It is also possible to unbind each view separately without affecting other bindings.

You can specify an error message per attribute by adding a property can also be a function returning a string.

The philosophy behind this way of using the plugin, is that you should be able to reuse your validation rules both to validate your model and to validate form input, as well as providing a simple way of notifying users about errors when they are populating forms. Validation does not provide any automatic/two-way binding between your model and the view, that's up you to implement (you can for instance use Backbone.stickit).

If none of the other validators can help you, the Custom Validator usually can.

It doesn't come with a predefined way of working; you write the code for validating your self.

The validation rules can either be an object with one of the built-in validators or a combination of two or more of them, or a function where you implement your own custom validation logic. To configure validation rules for objects, use dot notation in the name of the attribute, e.g See the built-in validators section for a list of the validators and patterns that you can use. Validation comes with a set of default error messages.

If you don't like to use those, you can either override them, or you can specify error messages where you declare validation rules on the model.

If you are using on the server you can also reuse your models and validation on the server side. You can download the raw source from Git Hub, see the annotated source or use the links below for the latest stable version. You only need to have Backbone (including underscore.js) in your page before including the Backbone. If you are using the default implementation of the callbacks, you also need to include j Query.

The plugin is tested with, and should work with the following versions of To configure your validation rules, simply add a validation property with a property for each attribute you want to validate on your model.

It is possible to bind several views to the same model.