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

fix: ✨ allows users to enter accented name characters #7832

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
67d531f
fix: :sparkles: allows users to enter accented name characters
shaheer-deriv Mar 7, 2023
4bbe640
chore: :wastebasket: removes unused 'letter_symbol' variable
shaheer-deriv Mar 8, 2023
9ce7b7a
Merge branch 'binary-com:master' into shaheer/90186/last-name-input-v…
shaheer-deriv Mar 8, 2023
94c7ea8
fix: :bug: allows accented characters in name for existing users
shaheer-deriv Mar 8, 2023
0d1bf15
Merge branch 'binary-com:master' into shaheer/90186/last-name-input-v…
shaheer-deriv Mar 9, 2023
bc44028
Merge branch 'binary-com:master' into shaheer/90186/last-name-input-v…
shaheer-deriv Mar 13, 2023
8ff10d7
Merge branch 'binary-com:master' into shaheer/90186/last-name-input-v…
shaheer-deriv Mar 14, 2023
d78d579
Merge branch 'binary-com:master' into shaheer/90186/last-name-input-v…
shaheer-deriv Mar 15, 2023
7b571bf
Merge branch 'master' into shaheer/90186/last-name-input-validation
shaheer-deriv Mar 15, 2023
fd27880
docs: :pencil2: comment on the regex used for name validation
shaheer-deriv Mar 15, 2023
20e0d2a
resused regex function
shaheer-deriv Mar 16, 2023
449e5bf
Merge branch 'master' into shaheer/90186/last-name-input-validation
shaheer-deriv Mar 16, 2023
c5afae2
fix: :memo: imported reused regex function
shaheer-deriv Mar 16, 2023
de4037d
Merge branch 'master' into shaheer/90186/last-name-input-validation
shaheer-deriv Mar 16, 2023
b2d392c
fix: :memo: comment on regex function used
shaheer-deriv Mar 16, 2023
ef6e34d
Merge branch 'master' into shaheer/90186/last-name-input-validation
shaheer-deriv Mar 17, 2023
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
4 changes: 2 additions & 2 deletions packages/account/src/Configs/personal-details-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const personal_details_config = ({ residence_list, account_settings, is_appstore
rules: [
['req', localize('First name is required.')],
['length', localize('First name should be between 2 and 50 characters.'), { min: 2, max: 50 }],
['letter_symbol', getErrorMessages().letter_symbol()],
['name', getErrorMessages().name()],
],
},
last_name: {
Expand All @@ -38,7 +38,7 @@ const personal_details_config = ({ residence_list, account_settings, is_appstore
rules: [
['req', localize('Last name is required.')],
['length', localize('Last name should be between 2 and 50 characters.'), { min: 2, max: 50 }],
['letter_symbol', getErrorMessages().letter_symbol()],
['name', getErrorMessages().name()],
],
},
date_of_birth: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
routes,
WS,
useIsMounted,
validName,
} from '@deriv/shared';
import { Localize, localize } from '@deriv/translations';
import { withRouter } from 'react-router';
Expand Down Expand Up @@ -314,8 +315,6 @@ export const PersonalDetailsForm = ({
}

validateValues(val => val, required_fields, localize('This field is required'));
const only_alphabet_fields = ['first_name', 'last_name'];
validateValues(validLetterSymbol, only_alphabet_fields, localize('Only alphabet is allowed'));

const residence_fields = ['citizen'];
const validateResidence = val => getLocation(residence_list, val, 'value');
Expand Down Expand Up @@ -351,12 +350,19 @@ export const PersonalDetailsForm = ({

const min_name = 2;
const max_name = 50;
if (values.first_name && !validLength(values.first_name.trim(), { min: min_name, max: max_name })) {
errors.first_name = localize('You should enter 2-50 characters.');
}
if (values.last_name && !validLength(values.last_name.trim(), { min: min_name, max: max_name })) {
errors.last_name = localize('You should enter 2-50 characters.');
}
const validateName = (name, field) => {
if (name) {
if (!validLength(name.trim(), { min: min_name, max: max_name })) {
errors[field] = localize('You should enter 2-50 characters.');
} else if (!validName(name)) {
// validName() has the exact regex used at the backend for allowing non digit characters including accented unicode characters.
// two or more space between name not allowed.
errors[field] = localize('Letters, spaces, periods, hyphens, apostrophes only.');
}
}
};
validateName(values.first_name, 'first_name');
validateName(values.last_name, 'last_name');

if (values.phone) {
// minimum characters required is 9 numbers (excluding +- signs or space)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Constants/form-error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const FORM_ERROR_MESSAGES = {
}),
email: () => localize('Invalid email address.'),
general: () => localize('Only letters, numbers, space, hyphen, period, and apostrophe are allowed.'),
letter_symbol: () => localize('Letters, spaces, periods, hyphens, apostrophes only'),
name: () => localize('Letters, spaces, periods, hyphens, apostrophes only.'),
password: () => localize('Password should have lower and uppercase English letters with numbers.'),
po_box: () => localize('P.O. Box is not accepted in address'),
phone: () => localize('Please enter a valid phone number (e.g. +15417541234).'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const validPostCode = (value: string) => value === '' || /^[A-Za-z0-9][A-
export const validTaxID = (value: string) => /(?!^$|\s+)[A-Za-z0-9./\s-]$/.test(value);
export const validPhone = (value: string) => /^\+?([0-9-]+\s)*[0-9-]+$/.test(value);
export const validLetterSymbol = (value: string) => /^[A-Za-z]+([a-zA-Z.' -])*[a-zA-Z.' -]+$/.test(value);
export const validName = (value: string) => /^(?!.*\s{2,})[\p{L}\s'.-]{2,50}$/u.test(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the same regex as the above. reuse the validName function in personal-details.jsx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks @yashim-deriv. your change is committed to the code.

export const validLength = (value = '', options: TOptions) =>
(options.min ? value.length >= options.min : true) && (options.max ? value.length <= options.max : true);
export const validPassword = (value: string) => /(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]+/.test(value);
Expand Down Expand Up @@ -108,9 +109,9 @@ const initPreBuildDVRs = () => ({
message: form_error_messages.general,
},
length: { func: validLength, message: '' }, // Message will be set in validLength function on initiation
letter_symbol: {
func: validLetterSymbol,
message: form_error_messages.letter_symbol,
name: {
func: validName,
message: form_error_messages.name,
},
number: {
func: (...args: [string, TOptions, Record<string, string | boolean>]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type TFormErrorMessagesTypes = Record<
| 'barrier'
| 'email'
| 'general'
| 'letter_symbol'
| 'name'
| 'password'
| 'po_box'
| 'phone'
Expand Down