Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display error message for symbols in legal name #15989

Merged
merged 4 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ const CONST = {
PHONE_E164_PLUS: /^\+?[1-9]\d{1,14}$/,
PHONE_WITH_SPECIAL_CHARS: /^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?\s*$/,
ALPHABETIC_CHARS: /[a-zA-Z]+/,
ALPHABETIC_CHARS_WITH_NUMBER: /^[a-zA-Z0-9 ]*$/,
POSITIVE_INTEGER: /^\d+$/,
NON_ALPHA_NUMERIC: /[^A-Za-z0-9+]/g,
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.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ export default {
error: {
dateShouldBeBefore: ({dateString}) => `Date should be before ${dateString}.`,
dateShouldBeAfter: ({dateString}) => `Date should be after ${dateString}.`,
hasInvalidCharacter: 'Name can only include letters and numbers.',
},
},
resendValidationForm: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ export default {
error: {
dateShouldBeBefore: ({dateString}) => `La fecha debe ser anterior a ${dateString}.`,
dateShouldBeAfter: ({dateString}) => `La fecha debe ser posterior a ${dateString}.`,
hasInvalidCharacter: 'El nombre solo puede contener letras y números.',
Copy link
Contributor

Choose a reason for hiding this comment

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

@PauloGasparSv Can you please verify if it is correct translation.

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM!

},
},
resendValidationForm: {
Expand Down
11 changes: 11 additions & 0 deletions src/libs/ValidationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,16 @@ function isValidDisplayName(name) {
return !name.includes(',') && !name.includes(';');
}

/**
* Checks that the provided legal name doesn't contain special characters
*
* @param {String} name
* @returns {Boolean}
*/
function isValidLegalName(name) {
return CONST.REGEX.ALPHABETIC_CHARS_WITH_NUMBER.test(name);
}

/**
* Checks if the provided string includes any of the provided reserved words
*
Expand Down Expand Up @@ -449,5 +459,6 @@ export {
isValidTaxID,
isValidValidateCode,
isValidDisplayName,
isValidLegalName,
doesContainReservedWord,
};
8 changes: 4 additions & 4 deletions src/pages/settings/Profile/PersonalDetails/LegalNamePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ class LegalNamePage extends Component {
validate(values) {
const errors = {};

if (!ValidationUtils.isValidDisplayName(values.legalFirstName)) {
errors.legalFirstName = this.props.translate('personalDetails.error.hasInvalidCharacter');
if (!ValidationUtils.isValidLegalName(values.legalFirstName)) {
errors.legalFirstName = this.props.translate('privatePersonalDetails.error.hasInvalidCharacter');
} else if (_.isEmpty(values.legalFirstName)) {
errors.legalFirstName = this.props.translate('common.error.fieldRequired');
}

if (!ValidationUtils.isValidDisplayName(values.legalLastName)) {
errors.legalLastName = this.props.translate('personalDetails.error.hasInvalidCharacter');
if (!ValidationUtils.isValidLegalName(values.legalLastName)) {
errors.legalLastName = this.props.translate('privatePersonalDetails.error.hasInvalidCharacter');
} else if (_.isEmpty(values.legalLastName)) {
errors.legalLastName = this.props.translate('common.error.fieldRequired');
}
Expand Down