Skip to content

Commit

Permalink
Merge pull request #32609 from Expensify/revert-31685-fix/31385
Browse files Browse the repository at this point in the history
Revert "Only allow alphabetic and latin characters for some fields in `CompanyStep`"
  • Loading branch information
Beamanator authored Dec 7, 2023
2 parents a2cf591 + f4a3bcf commit 20ef4d6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 55 deletions.
94 changes: 47 additions & 47 deletions src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ 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 (!CONST.REGEX.ANY_VALUE.test(value)) {
return false;
}

return !CONST.REGEX.PO_BOX.test(value);
}

/**
* Validate date fields
*/
Expand Down Expand Up @@ -193,6 +204,40 @@ function isValidWebsite(url: string): boolean {
return new RegExp(`^${URL_REGEX_WITH_REQUIRED_PROTOCOL}$`, 'i').test(url) && isLowerCase;
}

function validateIdentity(identity: Record<string, string>): Record<string, boolean> {
const requiredFields = ['firstName', 'lastName', 'street', 'city', 'zipCode', 'state', 'ssnLast4', 'dob'];
const errors: Record<string, boolean> = {};

// 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;
Expand Down Expand Up @@ -259,51 +304,6 @@ function isValidPersonName(value: string) {
return /^[^\d^!#$%*=<>;{}"]+$/.test(value);
}

/**
* 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);
}

function validateIdentity(identity: Record<string, string>): Record<string, boolean> {
const requiredFields = ['firstName', 'lastName', 'street', 'city', 'zipCode', 'state', 'ssnLast4', 'dob'];
const errors: Record<string, boolean> = {};

// 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
*/
Expand Down Expand Up @@ -384,6 +384,7 @@ export {
meetsMinimumAgeRequirement,
meetsMaximumAgeRequirement,
getAgeRequirementError,
isValidAddress,
isValidDate,
isValidPastDate,
isValidSecurityCode,
Expand All @@ -395,6 +396,7 @@ export {
getFieldRequiredErrors,
isValidUSPhone,
isValidWebsite,
validateIdentity,
isValidTwoFactorCode,
isNumericWithSpecialChars,
isValidRoutingNumber,
Expand All @@ -407,8 +409,6 @@ export {
isValidValidateCode,
isValidDisplayName,
isValidLegalName,
isValidAddress,
validateIdentity,
doesContainReservedWord,
isNumeric,
isValidAccountRoute,
Expand Down
8 changes: 0 additions & 8 deletions src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ 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';
}
Expand All @@ -100,10 +96,6 @@ 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';
}
Expand Down

0 comments on commit 20ef4d6

Please sign in to comment.