Skip to content

Commit

Permalink
Merge pull request #30674 from tienifr/fix/27390
Browse files Browse the repository at this point in the history
Fix: Name is not validated in Connect Bank account page
  • Loading branch information
stitesExpensify authored Nov 29, 2023
2 parents ef58238 + e9a556e commit 2f9ae2d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ function isValidLegalName(name: string): boolean {
return CONST.REGEX.ALPHABETIC_AND_LATIN_CHARS.test(name);
}

/**
* Checks that the provided name doesn't contain special characters or numbers
*/
function isValidPersonName(value: string) {
return /^[^\d^!#$%*=<>;{}"]+$/.test(value);
}

/**
* Checks if the provided string includes any of the provided reserved words
*/
Expand Down Expand Up @@ -407,4 +414,5 @@ export {
isValidAccountRoute,
isValidRecoveryCode,
prepareValues,
isValidPersonName,
};
8 changes: 8 additions & 0 deletions src/pages/ReimbursementAccount/RequestorStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ const validate = (values) => {
}
}

if (values.firstName && !ValidationUtils.isValidPersonName(values.firstName)) {
errors.firstName = 'bankAccount.error.firstName';
}

if (values.lastName && !ValidationUtils.isValidPersonName(values.lastName)) {
errors.lastName = 'bankAccount.error.lastName';
}

if (values.ssnLast4 && !ValidationUtils.isValidSSNLastFour(values.ssnLast4)) {
errors.ssnLast4 = 'bankAccount.error.ssnLast4';
}
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/ValidationUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,18 @@ describe('ValidationUtils', () => {
expect(ValidationUtils.isValidAccountRoute('123aaa')).toBe(false);
});
});

describe('ValidatePersonName', () => {
test('Valid person name', () => {
expect(ValidationUtils.isValidPersonName('test name')).toBe(true);
expect(ValidationUtils.isValidPersonName(`X Æ A test`)).toBe(true);
expect(ValidationUtils.isValidPersonName(`a hyphenated-name`)).toBe(true);
});

test('Invalid person name', () => {
expect(ValidationUtils.isValidPersonName('123 test')).toBe(false);
expect(ValidationUtils.isValidPersonName('test #$')).toBe(false);
expect(ValidationUtils.isValidPersonName('test123$')).toBe(false);
});
});
});

0 comments on commit 2f9ae2d

Please sign in to comment.