- 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");
}
}
}
推薦閱讀
- Designing Purpose:Built Drones for Ardupilot Pixhawk 2.1
- Windows Vista基礎(chǔ)與應(yīng)用精品教程
- Implementing Cisco UCS Solutions
- Kali Linux滲透測(cè)試全流程詳解
- 計(jì)算機(jī)系統(tǒng)開(kāi)發(fā)與優(yōu)化實(shí)戰(zhàn)
- Mobile First Design with HTML5 and CSS3
- Linux系統(tǒng)安全基礎(chǔ):二進(jìn)制代碼安全性分析基礎(chǔ)與實(shí)踐
- Joomla! 3 Template Essentials
- 嵌入式系統(tǒng)及其應(yīng)用(第三版)
- 一學(xué)就會(huì):Windows Vista應(yīng)用完全自學(xué)手冊(cè)
- 計(jì)算機(jī)系統(tǒng)的自主設(shè)計(jì)
- Social Data Visualization with HTML5 and JavaScript
- iOS 10 開(kāi)發(fā)指南
- Mastering Windows 8 C++ App Development
- 鴻蒙入門(mén):HarmonyOS應(yīng)用開(kāi)發(fā)