Skip to content

Commit

Permalink
chore: update validation check from object to function (#13037)
Browse files Browse the repository at this point in the history
  • Loading branch information
suisin-deriv authored and heorhi-deriv committed Jan 18, 2024
1 parent bac6c64 commit ee7b3d4
Showing 1 changed file with 57 additions and 50 deletions.
107 changes: 57 additions & 50 deletions packages/account/src/Sections/Profile/PersonalDetails/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,61 @@ import * as Yup from 'yup';
import { address_permitted_special_characters_message, getLocation, toMoment } from '@deriv/shared';
import { GetSettings, ResidenceList, StatesList } from '@deriv/api-types';

const BaseSchema = Yup.object().shape({
first_name: Yup.string()
.required(localize('First name is required.'))
.min(2, localize('You should enter 2-50 characters.'))
.max(50, localize('You should enter 2-50 characters.'))
.matches(/^(?!.*\s{2,})[\p{L}\s'.-]{2,50}$/u, localize('Letters, spaces, periods, hyphens, apostrophes only.')),
last_name: Yup.string()
.required(localize('Last name is required.'))
.min(2, localize('You should enter 2-50 characters.'))
.max(50, localize('You should enter 2-50 characters.'))
.matches(/^(?!.*\s{2,})[\p{L}\s'.-]{2,50}$/u, localize('Letters, spaces, periods, hyphens, apostrophes only.')),
phone: Yup.string()
.required(localize('Phone is required.'))
.min(9, localize('You should enter 9-35 numbers.'))
.max(35, localize('You should enter 9-35 characters.'))
.matches(/^\+?([0-9-]+\s)*[0-9-]+$/, localize('Please enter a valid phone number (e.g. +15417541234).')),
address_line_1: Yup.string()
.trim()
.required(localize('First line of address is required.'))
.max(70, localize('Should be less than 70.'))
.matches(
/^[\p{L}\p{Nd}\s'.,:;()\u00b0@#/-]{0,70}$/u,
localize('Use only the following special characters: {{permitted_characters}}', {
permitted_characters: address_permitted_special_characters_message,
interpolation: { escapeValue: false },
})
),
address_line_2: Yup.string()
.trim()
.max(70, localize('Should be less than 70.'))
.matches(
/^[\p{L}\p{Nd}\s'.,:;()\u00b0@#/-]{0,70}$/u,
localize('Use only the following special characters: {{permitted_characters}}', {
permitted_characters: address_permitted_special_characters_message,
interpolation: { escapeValue: false },
})
),
address_city: Yup.string()
.required(localize('Town/City is required.'))
.max(70, localize('Should be less than 70.'))
.matches(
/^[A-Za-z]+(?:[.' -]*[A-Za-z]+){1,70}$/,
localize('Only letters, space, hyphen, period, and apostrophe are allowed.')
),
address_postcode: Yup.string()
.max(20, localize('Please enter a Postal/ZIP code under 20 chatacters.'))
.matches(/^[A-Za-z0-9][A-Za-z0-9\s-]*$/, localize('Only letters, numbers, space, and hyphen are allowed.')),
});
const getBaseSchema = () =>
Yup.object().shape({
first_name: Yup.string()
.required(localize('First name is required.'))
.min(2, localize('You should enter 2-50 characters.'))
.max(50, localize('You should enter 2-50 characters.'))
.matches(
/^(?!.*\s{2,})[\p{L}\s'.-]{2,50}$/u,
localize('Letters, spaces, periods, hyphens, apostrophes only.')
),
last_name: Yup.string()
.required(localize('Last name is required.'))
.min(2, localize('You should enter 2-50 characters.'))
.max(50, localize('You should enter 2-50 characters.'))
.matches(
/^(?!.*\s{2,})[\p{L}\s'.-]{2,50}$/u,
localize('Letters, spaces, periods, hyphens, apostrophes only.')
),
phone: Yup.string()
.required(localize('Phone is required.'))
.min(9, localize('You should enter 9-35 numbers.'))
.max(35, localize('You should enter 9-35 characters.'))
.matches(/^\+?([0-9-]+\s)*[0-9-]+$/, localize('Please enter a valid phone number (e.g. +15417541234).')),
address_line_1: Yup.string()
.trim()
.required(localize('First line of address is required.'))
.max(70, localize('Should be less than 70.'))
.matches(
/^[\p{L}\p{Nd}\s'.,:;()\u00b0@#/-]{0,70}$/u,
localize('Use only the following special characters: {{permitted_characters}}', {
permitted_characters: address_permitted_special_characters_message,
interpolation: { escapeValue: false },
})
),
address_line_2: Yup.string()
.trim()
.max(70, localize('Should be less than 70.'))
.matches(
/^[\p{L}\p{Nd}\s'.,:;()\u00b0@#/-]{0,70}$/u,
localize('Use only the following special characters: {{permitted_characters}}', {
permitted_characters: address_permitted_special_characters_message,
interpolation: { escapeValue: false },
})
),
address_city: Yup.string()
.required(localize('Town/City is required.'))
.max(70, localize('Should be less than 70.'))
.matches(
/^[A-Za-z]+(?:[.' -]*[A-Za-z]+){1,70}$/,
localize('Only letters, space, hyphen, period, and apostrophe are allowed.')
),
address_postcode: Yup.string()
.max(20, localize('Please enter a Postal/ZIP code under 20 chatacters.'))
.matches(/^[A-Za-z0-9][A-Za-z0-9\s-]*$/, localize('Only letters, numbers, space, and hyphen are allowed.')),
});

export const getPersonalDetailsInitialValues = (
account_settings: GetSettings,
Expand Down Expand Up @@ -151,8 +158,8 @@ export const makeSettingsRequest = (
};

export const getPersonalDetailsValidationSchema = (is_eu: boolean) => {
if (!is_eu) return BaseSchema;
return BaseSchema.concat(
if (!is_eu) return getBaseSchema();
return getBaseSchema().concat(
Yup.object().shape({
tax_identification_number: Yup.string()
.required(localize('TIN is required.'))
Expand Down

1 comment on commit ee7b3d4

@vercel
Copy link

@vercel vercel bot commented on ee7b3d4 Jan 18, 2024

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

deriv-app – ./

binary.sx
deriv-app.vercel.app
deriv-app-git-master.binary.sx
deriv-app.binary.sx

Please sign in to comment.