React Bootstrap个人联系人管理器开发全解析
1. 数据验证
在开发过程中,数据验证是确保输入数据质量的重要环节。我们对地址、姓名和电话号码进行验证,具体如下:
1.1 地址验证
地址验证较为直接,我们为地址的第一行、城镇和郡应用最小长度验证器,为邮政编码应用正则表达式验证器。以下是具体代码:
public Validate(state: IPersonState, errors: string[]): void {
if (!this.minLengthValidator.IsValid(state.Address1)) {
errors.push("Address line 1 must be greater than 5 characters");
}
if (!this.minLengthValidator.IsValid(state.Town)) {
errors.push("Town must be greater than 5 characters");
}
if (!this.minLengthValidator.IsValid(state.County)) {
errors.push("County must be greater than 5 characters");
}
if (!this.zipCodeValidator.IsValid(state.Postcode)) {
errors.push("The postal/zip code is invalid");
}
}
超级会员免费看
订阅专栏 解锁全文
922

被折叠的 条评论
为什么被折叠?



