Extending the customer model
You also need to validate the customer data. These are the rules for validation:
- A first name is required
- A last name is required and it needs a minimum of three characters
- An address is required and it needs a minimum of five characters
- An e-mail address is required and must match the built-in e-mail pattern
- The zip code is required and must contain five numbers
To achieve this task, make some updates in the code, as follows:
- Extend the customer object in the
models/Customer.js
file:var firstName = ko.observable('').extend({ required: true }); var lastName = ko.observable('').extend({ required: true, minLength: 3 }); var fullName = ko.computed(function(){ return firstName() + ' ' + lastName(); }); var address = ko.observable(''). ...
Get KnockoutJS Essentials 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.