-
Notifications
You must be signed in to change notification settings - Fork 300
pattern validator
thedersen edited this page Jan 21, 2012
·
4 revisions
var SomeModel = Backbone.Model.extend({
validation: {
email: {
pattern: /^sample/
}
}
});
- value not matching pattern is invalid
- value matching pattern is valid
- when required is not specified null is invalid
- when required is not specified undefined is invalid
- when required:false undefined is valid
- when required:false null is valid
- when required:true undefined is invalid
- when required:true null is invalid
Backbone.Validation also comes with some common patterns included: url, email and number. Instead of specifying a regular expression, specify the name of the pattern you want to use:
var SomeModel = Backbone.Model.extend({
validation: {
email: {
pattern: 'url' | 'email' | 'number' | 'digits'
}
}
});
- email pattern matches all valid email addresses
- email pattern is case insensitive
- url pattern matches all valid urls
- url pattern is case insensitive
- number pattern matches all numbers, including decimal numbers
- digits pattern matches single or multiple digits