Skip to content

Commit

Permalink
Accept numeric values only in transfer input
Browse files Browse the repository at this point in the history
  • Loading branch information
sandrine-ds committed Nov 24, 2023
1 parent 46731f4 commit c5cd8e0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
6 changes: 3 additions & 3 deletions clients/banking/src/components/NewMembershipWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import { projectConfiguration } from "../utils/projectId";
import { Router } from "../utils/routes";
import {
validateAddressLine,
validateBeneficiaryName,
validateBirthdate,
validateEmail,
validateName,
validateRequired,
} from "../utils/validations";

Expand Down Expand Up @@ -163,13 +163,13 @@ export const NewMembershipWizard = ({
firstName: {
initialValue: partiallySavedValues?.firstName ?? "",
strategy: "onBlur",
validate: validateName,
validate: validateBeneficiaryName,
sanitize: value => value.trim(),
},
lastName: {
initialValue: partiallySavedValues?.lastName ?? "",
strategy: "onBlur",
validate: validateName,
validate: validateBeneficiaryName,
sanitize: value => value.trim(),
},
birthDate: {
Expand Down
4 changes: 2 additions & 2 deletions clients/banking/src/components/TransferWizardBeneficiary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { P, match } from "ts-pattern";
import { GetIbanValidationDocument } from "../graphql/partner";
import { t } from "../utils/i18n";
import { printIbanFormat, validateIban } from "../utils/iban";
import { validateName, validateRequired } from "../utils/validations";
import { validateBeneficiaryName, validateRequired } from "../utils/validations";

export type Beneficiary = {
name: string;
Expand Down Expand Up @@ -54,7 +54,7 @@ export const TransferWizardBeneficiary = ({ initialBeneficiary, onSave }: Props)
const { Field, listenFields, submitForm } = useForm({
name: {
initialValue: initialBeneficiary?.name ?? "",
validate: validateName,
validate: validateBeneficiaryName,
},
iban: {
initialValue: initialBeneficiary?.iban ?? "",
Expand Down
21 changes: 21 additions & 0 deletions clients/banking/src/utils/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ export const validateName: Validator<string> = value => {
}

// This regex was copied from the backend to ensure that the validation is the same
// Matches all unicode letters, spaces, dashes, apostrophes, commas, and single quotes
const isValid = value.match(
/^(?:[A-Za-zÀ-ÖÙ-öù-ƿDŽ-ʯʹ-ʽΈ-ΊΎ-ΡΣ-ҁҊ-Ֆա-ևႠ-Ⴥა-ჺᄀ-፜፩-ᎏᵫ-ᶚḀ-῾ⴀ-ⴥ⺀-⿕ぁ-ゖゝ-ㇿ㋿-鿯鿿-ꒌꙀ-ꙮꚀ-ꚙꜦ-ꞇꞍ-ꞿꥠ-ꥼA-Za-z]| |'|-|Ά|Ό|,)*$/,
);

if (!isValid) {
return t("common.form.invalidName");
}
};

//Beneficiary name input must accept numeric value, unlike other validation name
export const validateBeneficiaryName: Validator<string> = value => {
if (!value) {
return t("common.form.required");
}

// Rule copied from the backend
if (value.length > 100) {
return t("common.form.invalidName");
}

// Matches all unicode letters, spaces, dashes, apostrophes, commas, and single quotes
const isValid = value.match(
/^(?:[A-Za-zÀ-ÖÙ-öù-ƿDŽ-ʯʹ-ʽΈ-ΊΎ-ΡΣ-ҁҊ-Ֆա-ևႠ-Ⴥა-ჺᄀ-፜፩-ᎏᵫ-ᶚḀ-῾ⴀ-ⴥ⺀-⿕ぁ-ゖゝ-ㇿ㋿-鿯鿿-ꒌꙀ-ꙮꚀ-ꚙꜦ-ꞇꞍ-ꞿꥠ-ꥼA-Za-z]| |'|-|Ά|Ό|,|[1-9])*$/,
Expand Down

0 comments on commit c5cd8e0

Please sign in to comment.