Skip to content

Commit

Permalink
fix: validation to reject british pound as a special character
Browse files Browse the repository at this point in the history
  • Loading branch information
shontzu-deriv committed Sep 12, 2024
1 parent 3bf6c2e commit dbf73d3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/cfd/src/Helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
validPassword,
validMT5Password,
mobileOSDetectAsync,
hasBritishPound,
} from '@deriv/shared';
import { localize } from '@deriv/translations';
import { TCFDsPlatformType, TDetailsOfEachMT5Loginid, TMobilePlatforms } from 'Components/props.types';
Expand Down Expand Up @@ -140,7 +141,7 @@ const validatePassword = (password: string): string | undefined => {
max_number: 16,
});
} else if (!validPassword(password)) {
return getErrorMessages().password();
return hasBritishPound(password) ? getErrorMessages().special_characters() : getErrorMessages().password();
} else if (!validMT5Password(password)) {
return localize(
'Password must have at least one of these special characters: !&‘’*-“%+.#&(),:;?=@<>\\[]^_{}|~'
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/Constants/form-error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const FORM_ERROR_MESSAGES = {
general: () => localize('Only letters, numbers, space, hyphen, period, and apostrophe are allowed.'),
name: () => localize('Letters, spaces, periods, hyphens, apostrophes only.'),
password: () => localize('Password should have lower and uppercase English letters with numbers.'),
special_characters: () =>
localize('Password must have at least one of these special characters: !&‘’*-“%+.#&(),:;?=@<>\\[]^_{}|~'),
po_box: () => localize('P.O. Box is not accepted in address'),
phone: () => localize('Please enter a valid phone number (e.g. +15417541234).'),
postcode: () => localize('Only letters, numbers, space and hyphen are allowed.'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const validName = (value: string) => /^(?!.*\s{2,})(?!\s)[\p{L}\s'.-]{1,5
export const validLength = (value = '', options: TOptions) =>
(options.min ? value.length >= Number(options.min) : true) &&
(options.max ? value.length <= Number(options.max) : true);
export const hasBritishPound = (value: string) => /£/.test(value);
export const validPassword = (value: string) => /^(?=.*[a-z])(?=.*\d)(?=.*[A-Z])[!-~]{8,25}$/.test(value);
export const validEmail = (value: string) => /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$/.test(value);
const validBarrier = (value: string) => /^[+-]?\d+\.?\d*$/.test(value);
Expand Down

0 comments on commit dbf73d3

Please sign in to comment.