Validating model data

Usually, on frontend applications, the inputs are validated with UI plugins such as jQuery Validation, which focuses on the user interface. In other words, the data is validated directly on the DOM. However, on bigger applications that would not be the best approach.

Validations in Backbone can be done manually or through plugins. Of course, the best approach is to use a plugin because it saves time and effort, but before we learn how to use the backbone.validation plugin, I want to show you how native validation works.

Manual validation

Backbone models have three properties to help us validate the model data: validate(), validationError(), and isValid(). The validate()method should return nothing if the model data is correct, ...

Get Mastering Backbone.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.