官术网_书友最值得收藏!

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");
}
}
}

主站蜘蛛池模板: 汉源县| 太谷县| 新野县| 大埔县| 无锡市| 宜良县| 双辽市| 蕲春县| 大姚县| 博客| 万荣县| 天镇县| 河北省| 永川市| 肃宁县| 固安县| 常熟市| 天柱县| 咸阳市| 左贡县| 乌兰县| 房产| 清流县| 洪江市| 广南县| 博罗县| 两当县| 香格里拉县| 莱州市| 文昌市| 繁昌县| 嘉祥县| 龙井市| 鸡泽县| 玛纳斯县| 新津县| 乌兰察布市| 永和县| 仁寿县| 土默特右旗| 新疆|