- 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內核完全注釋(20周年版·第2版)
- Extending Puppet
- 高性能Linux服務器構建實戰:運維監控、性能調優與集群應用
- 混沌工程:復雜系統韌性實現之道
- 嵌入式系統原理及開發
- 無蘋果不生活 The New iPad隨身寶典
- Ceph分布式存儲實戰
- Linux內核設計的藝術:圖解Linux操作系統架構設計與實現原理
- 分布式高可用架構之道
- Building Telephony Systems With Asterisk
- Linux網絡配置與安全管理
- Learning Joomla! 3 Extension Development(Third Edition)
- Getting Started with Citrix XenApp 6.5
- Instant Responsive Web Design
- 分布式實時處理系統:原理、架構與實現