Introduction
Welcome to the "Demonstrating Backbone.js" article series. This article demonstrates how to create and use validations in Backbone.js. This article starts with the concept of Backbone.js and various components of it. Previous articles have provided an introduction to views and the implementation of routers and collections. You can get them from the following:
- Demonstrating Backbone.js: Implement View
- Demonstrating Backbone.js: Implement View Part 1
- Demonstrating Backbone.js: Implement View Part 2
- Demonstrating Backbone.js: Implement View Part 3
- Demonstrating Backbone.js: Implement View Part 4
- Demonstrating Backbone.js :Implement View Part 5
- Demonstrating Backbone.js :Implement Routers Part 1
- Demonstrating Backbone.js :Implement Collections
- Demonstrating Backbone.js :Implement Validations
- Demonstrating Backbone.js :Implement validatons Part 2
- Demonstrating Backbone.js :Implement validatons Part 3
- Method Validator
- Named Method Validator
- required
- acceptance
- min
- max
- range
- length
- minLength
- maxLength
- rangeLength
- oneOf
- equalTo
- pattern
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JavaScript.aspx.cs" Inherits="JavaScript.JavaScript" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="backbone/Jquery.js" type="text/javascript"></script>
<script src="backbone/underscore-min.js" type="text/javascript"></script>
<script src="backbone/backbone-min.js" type="text/javascript"></script>
<script src="backbone/backbone-validation-amd-min.js" type="text/javascript"></script>
<script src="backbone/backbone-validation-min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
var Area = Backbone.Model.extend({
validation: {
postalCode: {
length: 4
}
}
});
</script>
</body>
</html>
Minlength Validator<script type="text/javascript">
var User = Backbone.Model.extend({
validation: {
password: {
minLength: 8
}
}
});
</script>
<script type="text/javascript">
var User = Backbone.Model.extend({
validation: {
password: {
maxLength: 100
}
}
});
</script>
var user = Backbone.Model.extend({
validation: {
password: {
rangeLength: [6, 100]
}
}
});
</script>
var States = Backbone.Model.extend({
validation: {
state: {
oneOf: ['Andhrapradesh', 'Tamilnadu']
}
}
});
</script>
var User = Backbone.Model.extend({
validation: {
password: {
required: true
},
passwordRepeat: {
equalTo: 'password'
}
}
});
</script>
<script type="text/javascript">
var User = Backbone.Model.extend({
validation: {
email: {
pattern: 'email'
}
}
});
</script>
In this article, I explained how to use builtin validators in models in Backbone.js, In future articles we will understand them with a real-time application.

Join the conversation! Your thoughts help the community grow.