Skip to content

Commit ee7b3d4

Browse files
suisin-derivheorhi-deriv
authored andcommitted
chore: update validation check from object to function (#13037)
1 parent bac6c64 commit ee7b3d4

File tree

1 file changed

+57
-50
lines changed
  • packages/account/src/Sections/Profile/PersonalDetails

1 file changed

+57
-50
lines changed

packages/account/src/Sections/Profile/PersonalDetails/validation.ts

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,61 @@ import * as Yup from 'yup';
33
import { address_permitted_special_characters_message, getLocation, toMoment } from '@deriv/shared';
44
import { GetSettings, ResidenceList, StatesList } from '@deriv/api-types';
55

6-
const BaseSchema = Yup.object().shape({
7-
first_name: Yup.string()
8-
.required(localize('First name is required.'))
9-
.min(2, localize('You should enter 2-50 characters.'))
10-
.max(50, localize('You should enter 2-50 characters.'))
11-
.matches(/^(?!.*\s{2,})[\p{L}\s'.-]{2,50}$/u, localize('Letters, spaces, periods, hyphens, apostrophes only.')),
12-
last_name: Yup.string()
13-
.required(localize('Last name is required.'))
14-
.min(2, localize('You should enter 2-50 characters.'))
15-
.max(50, localize('You should enter 2-50 characters.'))
16-
.matches(/^(?!.*\s{2,})[\p{L}\s'.-]{2,50}$/u, localize('Letters, spaces, periods, hyphens, apostrophes only.')),
17-
phone: Yup.string()
18-
.required(localize('Phone is required.'))
19-
.min(9, localize('You should enter 9-35 numbers.'))
20-
.max(35, localize('You should enter 9-35 characters.'))
21-
.matches(/^\+?([0-9-]+\s)*[0-9-]+$/, localize('Please enter a valid phone number (e.g. +15417541234).')),
22-
address_line_1: Yup.string()
23-
.trim()
24-
.required(localize('First line of address is required.'))
25-
.max(70, localize('Should be less than 70.'))
26-
.matches(
27-
/^[\p{L}\p{Nd}\s'.,:;()\u00b0@#/-]{0,70}$/u,
28-
localize('Use only the following special characters: {{permitted_characters}}', {
29-
permitted_characters: address_permitted_special_characters_message,
30-
interpolation: { escapeValue: false },
31-
})
32-
),
33-
address_line_2: Yup.string()
34-
.trim()
35-
.max(70, localize('Should be less than 70.'))
36-
.matches(
37-
/^[\p{L}\p{Nd}\s'.,:;()\u00b0@#/-]{0,70}$/u,
38-
localize('Use only the following special characters: {{permitted_characters}}', {
39-
permitted_characters: address_permitted_special_characters_message,
40-
interpolation: { escapeValue: false },
41-
})
42-
),
43-
address_city: Yup.string()
44-
.required(localize('Town/City is required.'))
45-
.max(70, localize('Should be less than 70.'))
46-
.matches(
47-
/^[A-Za-z]+(?:[.' -]*[A-Za-z]+){1,70}$/,
48-
localize('Only letters, space, hyphen, period, and apostrophe are allowed.')
49-
),
50-
address_postcode: Yup.string()
51-
.max(20, localize('Please enter a Postal/ZIP code under 20 chatacters.'))
52-
.matches(/^[A-Za-z0-9][A-Za-z0-9\s-]*$/, localize('Only letters, numbers, space, and hyphen are allowed.')),
53-
});
6+
const getBaseSchema = () =>
7+
Yup.object().shape({
8+
first_name: Yup.string()
9+
.required(localize('First name is required.'))
10+
.min(2, localize('You should enter 2-50 characters.'))
11+
.max(50, localize('You should enter 2-50 characters.'))
12+
.matches(
13+
/^(?!.*\s{2,})[\p{L}\s'.-]{2,50}$/u,
14+
localize('Letters, spaces, periods, hyphens, apostrophes only.')
15+
),
16+
last_name: Yup.string()
17+
.required(localize('Last name is required.'))
18+
.min(2, localize('You should enter 2-50 characters.'))
19+
.max(50, localize('You should enter 2-50 characters.'))
20+
.matches(
21+
/^(?!.*\s{2,})[\p{L}\s'.-]{2,50}$/u,
22+
localize('Letters, spaces, periods, hyphens, apostrophes only.')
23+
),
24+
phone: Yup.string()
25+
.required(localize('Phone is required.'))
26+
.min(9, localize('You should enter 9-35 numbers.'))
27+
.max(35, localize('You should enter 9-35 characters.'))
28+
.matches(/^\+?([0-9-]+\s)*[0-9-]+$/, localize('Please enter a valid phone number (e.g. +15417541234).')),
29+
address_line_1: Yup.string()
30+
.trim()
31+
.required(localize('First line of address is required.'))
32+
.max(70, localize('Should be less than 70.'))
33+
.matches(
34+
/^[\p{L}\p{Nd}\s'.,:;()\u00b0@#/-]{0,70}$/u,
35+
localize('Use only the following special characters: {{permitted_characters}}', {
36+
permitted_characters: address_permitted_special_characters_message,
37+
interpolation: { escapeValue: false },
38+
})
39+
),
40+
address_line_2: Yup.string()
41+
.trim()
42+
.max(70, localize('Should be less than 70.'))
43+
.matches(
44+
/^[\p{L}\p{Nd}\s'.,:;()\u00b0@#/-]{0,70}$/u,
45+
localize('Use only the following special characters: {{permitted_characters}}', {
46+
permitted_characters: address_permitted_special_characters_message,
47+
interpolation: { escapeValue: false },
48+
})
49+
),
50+
address_city: Yup.string()
51+
.required(localize('Town/City is required.'))
52+
.max(70, localize('Should be less than 70.'))
53+
.matches(
54+
/^[A-Za-z]+(?:[.' -]*[A-Za-z]+){1,70}$/,
55+
localize('Only letters, space, hyphen, period, and apostrophe are allowed.')
56+
),
57+
address_postcode: Yup.string()
58+
.max(20, localize('Please enter a Postal/ZIP code under 20 chatacters.'))
59+
.matches(/^[A-Za-z0-9][A-Za-z0-9\s-]*$/, localize('Only letters, numbers, space, and hyphen are allowed.')),
60+
});
5461

5562
export const getPersonalDetailsInitialValues = (
5663
account_settings: GetSettings,
@@ -151,8 +158,8 @@ export const makeSettingsRequest = (
151158
};
152159

153160
export const getPersonalDetailsValidationSchema = (is_eu: boolean) => {
154-
if (!is_eu) return BaseSchema;
155-
return BaseSchema.concat(
161+
if (!is_eu) return getBaseSchema();
162+
return getBaseSchema().concat(
156163
Yup.object().shape({
157164
tax_identification_number: Yup.string()
158165
.required(localize('TIN is required.'))

0 commit comments

Comments
 (0)