diff --git a/src/libs/ValidationUtils.ts b/src/libs/ValidationUtils.ts index 9246f760f7bd..388020bc0d6d 100644 --- a/src/libs/ValidationUtils.ts +++ b/src/libs/ValidationUtils.ts @@ -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 */ @@ -407,4 +414,5 @@ export { isValidAccountRoute, isValidRecoveryCode, prepareValues, + isValidPersonName, }; diff --git a/src/pages/ReimbursementAccount/RequestorStep.js b/src/pages/ReimbursementAccount/RequestorStep.js index 69de88f12327..9c1e8345604f 100644 --- a/src/pages/ReimbursementAccount/RequestorStep.js +++ b/src/pages/ReimbursementAccount/RequestorStep.js @@ -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'; } diff --git a/tests/unit/ValidationUtilsTest.js b/tests/unit/ValidationUtilsTest.js index bdc1f11948ae..45de052f714d 100644 --- a/tests/unit/ValidationUtilsTest.js +++ b/tests/unit/ValidationUtilsTest.js @@ -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); + }); + }); });