From 72ae19e3da5bcfa52aca92e09a0ddf9f85c8f8d4 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 3 Jan 2024 15:57:30 +0700 Subject: [PATCH 1/2] not allow emojis in address --- src/libs/ValidationUtils.ts | 10 +++++++++- src/pages/ReimbursementAccount/CompanyStep.js | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index ba977312fcfb..a04b63865a3d 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -35,7 +35,7 @@ function validateCardNumber(value: string): boolean { * Validating that this is a valid address (PO boxes are not allowed) */ function isValidAddress(value: string): boolean { - if (!CONST.REGEX.ANY_VALUE.test(value)) { + if (!CONST.REGEX.ANY_VALUE.test(value) || CONST.REGEX.EMOJIS.test(value)) { return false; } @@ -306,6 +306,13 @@ function isValidRoutingNumber(routingNumber: string): boolean { return false; } +/** + * Checks that the provided name doesn't contain any emojis + */ +function isValidCompanyName(name: string) { + return !CONST.REGEX.EMOJIS.test(name); +} + /** * Checks that the provided name doesn't contain any commas or semicolons */ @@ -451,6 +458,7 @@ export { isValidRoomName, isValidTaxID, isValidValidateCode, + isValidCompanyName, isValidDisplayName, isValidLegalName, doesContainReservedWord, diff --git a/src/pages/ReimbursementAccount/CompanyStep.js b/src/pages/ReimbursementAccount/CompanyStep.js index a35fa596160a..b5deb5e31a17 100644 --- a/src/pages/ReimbursementAccount/CompanyStep.js +++ b/src/pages/ReimbursementAccount/CompanyStep.js @@ -88,6 +88,10 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul ]; const errors = ValidationUtils.getFieldRequiredErrors(values, requiredFields); + if (values.companyName && !ValidationUtils.isValidCompanyName(values.companyName)) { + errors.companyName = 'bankAccount.error.companyName'; + } + if (values.addressStreet && !ValidationUtils.isValidAddress(values.addressStreet)) { errors.addressStreet = 'bankAccount.error.addressStreet'; } @@ -96,6 +100,10 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul errors.addressZipCode = 'bankAccount.error.zipCode'; } + if (values.addressCity && !ValidationUtils.isValidAddress(values.addressCity)) { + errors.addressCity = 'bankAccount.error.addressCity'; + } + if (values.companyPhone && !ValidationUtils.isValidUSPhone(values.companyPhone, true)) { errors.companyPhone = 'bankAccount.error.phoneNumber'; } From 9ce24ae64f0328a4880714e219ae3c004fc944cb Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 3 Jan 2024 16:25:00 +0700 Subject: [PATCH 2/2] fix lint --- src/libs/ValidationUtils.ts | 4 ++-- src/pages/ReimbursementAccount/CompanyStep.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index a04b63865a3d..add7a72045c5 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -35,7 +35,7 @@ function validateCardNumber(value: string): boolean { * Validating that this is a valid address (PO boxes are not allowed) */ function isValidAddress(value: string): boolean { - if (!CONST.REGEX.ANY_VALUE.test(value) || CONST.REGEX.EMOJIS.test(value)) { + if (!CONST.REGEX.ANY_VALUE.test(value) || value.match(CONST.REGEX.EMOJIS)) { return false; } @@ -310,7 +310,7 @@ function isValidRoutingNumber(routingNumber: string): boolean { * Checks that the provided name doesn't contain any emojis */ function isValidCompanyName(name: string) { - return !CONST.REGEX.EMOJIS.test(name); + return !name.match(CONST.REGEX.EMOJIS); } /** diff --git a/src/pages/ReimbursementAccount/CompanyStep.js b/src/pages/ReimbursementAccount/CompanyStep.js index b5deb5e31a17..9f985e15a95e 100644 --- a/src/pages/ReimbursementAccount/CompanyStep.js +++ b/src/pages/ReimbursementAccount/CompanyStep.js @@ -96,14 +96,14 @@ function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaul errors.addressStreet = 'bankAccount.error.addressStreet'; } - if (values.addressZipCode && !ValidationUtils.isValidZipCode(values.addressZipCode)) { - errors.addressZipCode = 'bankAccount.error.zipCode'; - } - if (values.addressCity && !ValidationUtils.isValidAddress(values.addressCity)) { errors.addressCity = 'bankAccount.error.addressCity'; } + if (values.addressZipCode && !ValidationUtils.isValidZipCode(values.addressZipCode)) { + errors.addressZipCode = 'bankAccount.error.zipCode'; + } + if (values.companyPhone && !ValidationUtils.isValidUSPhone(values.companyPhone, true)) { errors.companyPhone = 'bankAccount.error.phoneNumber'; }