From 859d1eab2a5395ba4d190e1c3c9772bf59384348 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 22 Nov 2023 17:32:19 +0700 Subject: [PATCH 1/4] do not allow emojis for some fields in company step --- src/libs/ValidationUtils.ts | 2 +- src/pages/ReimbursementAccount/CompanyStep.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index 7c49006c10a5..af2ec32def0d 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -34,7 +34,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 (!isValidLegalName(value)) { return false; } diff --git a/src/pages/ReimbursementAccount/CompanyStep.js b/src/pages/ReimbursementAccount/CompanyStep.js index e31988fbb118..df91d8ab5120 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.isValidLegalName(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.isValidLegalName(values.addressCity)) { + errors.addressCity = 'bankAccount.error.addressCity'; + } + if (values.companyPhone && !ValidationUtils.isValidUSPhone(values.companyPhone, true)) { errors.companyPhone = 'bankAccount.error.phoneNumber'; } From 98ce9d163243c69d525cf2d4756b7fda3dfb1546 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 22 Nov 2023 17:51:51 +0700 Subject: [PATCH 2/4] rearrange function order --- src/libs/ValidationUtils.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index af2ec32def0d..d2e8384f59cc 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -30,17 +30,6 @@ function validateCardNumber(value: string): boolean { return sum % 10 === 0; } -/** - * Validating that this is a valid address (PO boxes are not allowed) - */ -function isValidAddress(value: string): boolean { - if (!isValidLegalName(value)) { - return false; - } - - return !CONST.REGEX.PO_BOX.test(value); -} - /** * Validate date fields */ @@ -296,6 +285,17 @@ function isValidLegalName(name: string): boolean { return CONST.REGEX.ALPHABETIC_AND_LATIN_CHARS.test(name); } +/** + * Validating that this is a valid address (PO boxes are not allowed) + */ +function isValidAddress(value: string): boolean { + if (!isValidLegalName(value)) { + return false; + } + + return !CONST.REGEX.PO_BOX.test(value); +} + /** * Checks if the provided string includes any of the provided reserved words */ @@ -376,7 +376,6 @@ export { meetsMinimumAgeRequirement, meetsMaximumAgeRequirement, getAgeRequirementError, - isValidAddress, isValidDate, isValidPastDate, isValidSecurityCode, @@ -401,6 +400,7 @@ export { isValidValidateCode, isValidDisplayName, isValidLegalName, + isValidAddress, doesContainReservedWord, isNumeric, isValidAccountRoute, From a9ecf92c01d097f257ef1bc0e8a209a69c3a73f3 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 22 Nov 2023 17:59:41 +0700 Subject: [PATCH 3/4] fix lint --- src/libs/ValidationUtils.ts | 70 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index d2e8384f59cc..736cafe3e4ce 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -192,40 +192,6 @@ function isValidWebsite(url: string): boolean { return new RegExp(`^${URL_REGEX_WITH_REQUIRED_PROTOCOL}$`, 'i').test(url); } -function validateIdentity(identity: Record): Record { - const requiredFields = ['firstName', 'lastName', 'street', 'city', 'zipCode', 'state', 'ssnLast4', 'dob']; - const errors: Record = {}; - - // Check that all required fields are filled - requiredFields.forEach((fieldName) => { - if (isRequiredFulfilled(identity[fieldName])) { - return; - } - errors[fieldName] = true; - }); - - if (!isValidAddress(identity.street)) { - errors.street = true; - } - - if (!isValidZipCode(identity.zipCode)) { - errors.zipCode = true; - } - - // dob field has multiple validations/errors, we are handling it temporarily like this. - if (!isValidDate(identity.dob) || !meetsMaximumAgeRequirement(identity.dob)) { - errors.dob = true; - } else if (!meetsMinimumAgeRequirement(identity.dob)) { - errors.dobAge = true; - } - - if (!isValidSSNLastFour(identity.ssnLast4)) { - errors.ssnLast4 = true; - } - - return errors; -} - function isValidUSPhone(phoneNumber = '', isCountryCodeOptional?: boolean): boolean { const phone = phoneNumber || ''; const regionCode = isCountryCodeOptional ? CONST.COUNTRY.US : undefined; @@ -296,6 +262,40 @@ function isValidAddress(value: string): boolean { return !CONST.REGEX.PO_BOX.test(value); } +function validateIdentity(identity: Record): Record { + const requiredFields = ['firstName', 'lastName', 'street', 'city', 'zipCode', 'state', 'ssnLast4', 'dob']; + const errors: Record = {}; + + // Check that all required fields are filled + requiredFields.forEach((fieldName) => { + if (isRequiredFulfilled(identity[fieldName])) { + return; + } + errors[fieldName] = true; + }); + + if (!isValidAddress(identity.street)) { + errors.street = true; + } + + if (!isValidZipCode(identity.zipCode)) { + errors.zipCode = true; + } + + // dob field has multiple validations/errors, we are handling it temporarily like this. + if (!isValidDate(identity.dob) || !meetsMaximumAgeRequirement(identity.dob)) { + errors.dob = true; + } else if (!meetsMinimumAgeRequirement(identity.dob)) { + errors.dobAge = true; + } + + if (!isValidSSNLastFour(identity.ssnLast4)) { + errors.ssnLast4 = true; + } + + return errors; +} + /** * Checks if the provided string includes any of the provided reserved words */ @@ -387,7 +387,6 @@ export { getFieldRequiredErrors, isValidUSPhone, isValidWebsite, - validateIdentity, isValidTwoFactorCode, isNumericWithSpecialChars, isValidRoutingNumber, @@ -401,6 +400,7 @@ export { isValidDisplayName, isValidLegalName, isValidAddress, + validateIdentity, doesContainReservedWord, isNumeric, isValidAccountRoute, From dadfc86f51d8cfc4f6157f756c6627e3d927d1dc Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 30 Nov 2023 23:36:41 +0700 Subject: [PATCH 4/4] fix merge error --- src/libs/ValidationUtils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index 49971c5a140b..0adacac4035a 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -189,7 +189,8 @@ function getAgeRequirementError(date: string, minimumAge: number, maximumAge: nu * http/https/ftp URL scheme required. */ function isValidWebsite(url: string): boolean { - return new RegExp(`^${URL_REGEX_WITH_REQUIRED_PROTOCOL}$`, 'i').test(url); + const isLowerCase = url === url.toLowerCase(); + return new RegExp(`^${URL_REGEX_WITH_REQUIRED_PROTOCOL}$`, 'i').test(url) && isLowerCase; } function isValidUSPhone(phoneNumber = '', isCountryCodeOptional?: boolean): boolean {