- Advanced TypeScript Programming Projects
- Peter O'Hanlon
- 96字
- 2021-06-24 13:27:14
Validating the name
The name validation is the simplest piece of validation we are going to write. This validation assumes that we have a minimum of one letter for the first name and two letters for the last name:
export class PersonValidation implements IValidation {
private readonly firstNameValidator : MinLengthValidator = new MinLengthValidator(1);
private readonly lastNameValidator : MinLengthValidator = new MinLengthValidator(2);
public Validate(state: IPersonState, errors: string[]): void {
if (!this.firstNameValidator.IsValid(state.FirstName)) {
errors.push("The first name is a minimum of 1 character");
}
if (!this.lastNameValidator.IsValid(state.FirstName)) {
errors.push("The last name is a minimum of 2 characters");
}
}
}
推薦閱讀
- pcDuino開發實戰
- 30天自制操作系統
- Linux網絡管理與配置(第2版)
- Designing Purpose:Built Drones for Ardupilot Pixhawk 2.1
- Windows Phone應用程序開發
- 高性能Linux服務器構建實戰:系統安全、故障排查、自動化運維與集群架構
- 嵌入式Linux應用開發菜鳥進階
- 數據中心系統工程及應用
- 嵌入式系統原理及開發
- 直播系統開發:基于Nginx與Nginx-rtmp-module
- AWS Development Essentials
- Linux內核設計的藝術:圖解Linux操作系統架構設計與實現原理
- 一學就會:Windows Vista應用完全自學手冊
- Distributed Computing with Go
- Windows 8實戰從入門到精通(超值版)