- 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");
}
}
}
推薦閱讀
- Linux網絡管理與配置(第2版)
- Linux操作系統基礎
- 無蘋果不生活 OS X Mountain Lion隨身寶典
- WindowsServer2012Hyper-V虛擬化部署與管理指南
- 嵌入式系統原理及開發
- INSTANT Migration from Windows Server 2008 and 2008 R2 to 2012 How-to
- 計算機系統:基于x86+Linux平臺
- Linux設備驅動開發
- Linux基礎使用與案例
- Red Hat Enterprise Linux 6.4網絡操作系統詳解
- Heroku Cloud Application Development
- Mastering Sass
- Linux系統管理初學者指南:基于CentOS 7.6
- Responsive Web Design with AngularJS
- Mastering Eclipse Plug-in Development