Skip to content
1 change: 1 addition & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3714,6 +3714,7 @@ const CONST = {
SPECIAL_CHARS_WITHOUT_NEWLINE: /((?!\n)[()-\s\t])/g,
DIGITS_AND_PLUS: /^\+?[0-9]*$/,
ALPHABETIC_AND_LATIN_CHARS: /^[\p{Script=Latin} ]*$/u,
ALPHABETIC_AND_LATIN_CHARS_WITH_HYPHEN: /^[\p{Script=Latin} -]*$/u,
Copy link
Contributor

@hungvu193 hungvu193 Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that we should only allow hyphen if it's followed by another character?

Otherwise, we can see something like this, it looks pretty weird and I don't think that's a valid name:

Screen.Recording.2025-12-07.at.22.23.11.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was exactly what I was asking. @JmillsExpensify @trjExpensify WDYT about the above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhm.. so let's take a step back on the history here.

Anything that's not empty is a valid name

So, has anything changed between our last outcome and now? If not, then we're still expecting anything but an empty value is a valid legal name. This time, can we please make sure:

  • Any BE changes that need to be made is done first before the FE changes.
  • We create a regression test and engage Applause to avoid coming back to square one.

Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm up if we decide to allow any name other than empty string on the BE, lemme know 🙇

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this issue, we have implemented stricter rules for our legal name validation. However, the current validation allows hyphen character that's not followed by another Latin character, please see my comment.

I'd suggest that we should only hyphen if it's followed by another Latin character. For example:

hans-vu is valid name while hans-, -hans aren't.

Let me know your thoughts 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this issue, we have implemented stricter rules for our legal name validation

What issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hungvu193 would you be able to raise a discussion in slack, that way we all can communicate faster :)

NON_ALPHABETIC_AND_NON_LATIN_CHARS: /[^\p{Script=Latin}]/gu,
POSITIVE_INTEGER: /^\d+$/,
PO_BOX: /\b[P|p]?(OST|ost)?\.?\s*[O|o|0]?(ffice|FFICE)?\.?\s*[B|b][O|o|0]?[X|x]?\.?\s+[#]?(\d+)\b/,
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2863,6 +2863,7 @@ const translations = {
dateShouldBeBefore: ({dateString}: DateShouldBeBeforeParams) => `Date should be before ${dateString}`,
dateShouldBeAfter: ({dateString}: DateShouldBeAfterParams) => `Date should be after ${dateString}`,
hasInvalidCharacter: 'Name can only include Latin characters',
hasInvalidCharacterWithHyphen: 'Name can only include Latin characters and hyphen',
incorrectZipFormat: ({zipFormat}: IncorrectZipFormatParams = {}) => `Incorrect zip code format${zipFormat ? ` Acceptable format: ${zipFormat}` : ''}`,
invalidPhoneNumber: `Please ensure the phone number is valid (e.g. ${CONST.EXAMPLE_PHONE_NUMBER})`,
},
Expand Down
6 changes: 3 additions & 3 deletions src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ function isValidDisplayName(name: string): boolean {
}

/**
* Checks that the provided legal name doesn't contain special characters
* Checks that the provided legal name doesn't contain special characters except hyphens when shouldAllowHyphen is passed as true.
*/
function isValidLegalName(name: string): boolean {
return CONST.REGEX.ALPHABETIC_AND_LATIN_CHARS.test(name);
function isValidLegalName(name: string, shouldAllowHyphen = false): boolean {
return shouldAllowHyphen ? CONST.REGEX.ALPHABETIC_AND_LATIN_CHARS_WITH_HYPHEN.test(name) : CONST.REGEX.ALPHABETIC_AND_LATIN_CHARS.test(name);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function LegalNamePage() {
if (typeof values.legalFirstName === 'string') {
if (!values.legalFirstName) {
errors.legalFirstName = translate('common.error.fieldRequired');
} else if (!isValidLegalName(values.legalFirstName)) {
addErrorMessage(errors, 'legalFirstName', translate('privatePersonalDetails.error.hasInvalidCharacter'));
} else if (!isValidLegalName(values.legalFirstName, true)) {
addErrorMessage(errors, 'legalFirstName', translate('privatePersonalDetails.error.hasInvalidCharacterWithHyphen'));
} else if (values.legalFirstName.length > CONST.LEGAL_NAME.MAX_LENGTH) {
addErrorMessage(
errors,
Expand All @@ -66,8 +66,8 @@ function LegalNamePage() {
if (typeof values.legalLastName === 'string') {
if (!values.legalLastName) {
errors.legalLastName = translate('common.error.fieldRequired');
} else if (!isValidLegalName(values.legalLastName)) {
addErrorMessage(errors, 'legalLastName', translate('privatePersonalDetails.error.hasInvalidCharacter'));
} else if (!isValidLegalName(values.legalLastName, true)) {
addErrorMessage(errors, 'legalLastName', translate('privatePersonalDetails.error.hasInvalidCharacterWithHyphen'));
} else if (values.legalLastName.length > CONST.LEGAL_NAME.MAX_LENGTH) {
addErrorMessage(
errors,
Expand Down
Loading