[new feature] AddressEdit: add postal-validator prop (#4067)

This commit is contained in:
neverland
2019-08-08 19:08:46 +08:00
committed by GitHub
parent f520c221a9
commit bc4323b128
3 changed files with 12 additions and 2 deletions

View File

@@ -24,6 +24,10 @@ const defaultData = {
isDefault: false
};
function isPostal(value) {
return /^\d{6}$/.test(value);
}
export default createComponent({
props: {
areaList: Object,
@@ -60,6 +64,10 @@ export default createComponent({
telValidator: {
type: Function,
default: isMobile
},
postalValidator: {
type: Function,
default: isPostal
}
},
@@ -183,7 +191,7 @@ export default createComponent({
case 'addressDetail':
return value ? '' : t('addressEmpty');
case 'postalCode':
return value && !/^\d{6}$/.test(value) ? t('postalEmpty') : '';
return value && !this.postalValidator(value) ? t('postalEmpty') : '';
}
},