Skip to content

Commit a83e165

Browse files
fix: Relax validation of names, to allow special characters, apostrophes and hyphens (#876)
* relax validation of names, to allow special characters, apostrophes and hyphens * fix: Empty commit to trigger CI * Fixes yup validation for email Signup test
1 parent 39b4dbc commit a83e165

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/components/Organisms/EmailSignUp/EmailSignUp.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import React from "react";
22
import "jest-styled-components";
33
import renderWithTheme from "../../../../tests/hoc/shallowWithTheme";
4-
import { EmailSignUp, validationSchema } from "./_EmailSignUp";
4+
import { EmailSignUp, buildEsuValidationSchema } from "./_EmailSignUp";
55
import RichText from "../../Atoms/RichText/RichText";
66
import { useForm, FormProvider } from "react-hook-form";
77
import { yupResolver } from "@hookform/resolvers/yup";
88

99
const DummyForm = () => {
1010
const formMethods = useForm({
1111
mode: "onBlur",
12-
resolver: yupResolver(validationSchema),
12+
resolver: yupResolver(buildEsuValidationSchema()),
1313
});
1414
const { handleSubmit } = formMethods;
1515

src/components/Organisms/shared/emailSignup/emailSignupConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ const buildEsuValidationSchema = overrides => {
3434
.string()
3535
.required('Please enter your first name')
3636
.matches(
37-
/^[A-Za-z][A-Za-z' -]*$/,
37+
/^\p{L}[\p{L}' -]*$/u,
3838
"This field only accepts letters and ' - and must start with a letter"
3939
)
4040
.max(25, 'Your first name must be between 1 and 25 characters'),
4141
[ESU_FIELDS.LAST_NAME]: yup
4242
.string()
4343
.required('Please enter your last name')
4444
.matches(
45-
/^[A-Za-z][A-Za-z' -]*$/,
45+
/^\p{L}[\p{L}' -]*$/u,
4646
"This field only accepts letters and ' - and must start with a letter"
4747
)
4848
.max(50, 'Your last name must be between 1 and 50 characters'),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { buildEsuValidationSchema, ESU_FIELDS } from './emailSignupConfig';
2+
3+
describe('buildEsuValidationSchema', () => {
4+
const schema = buildEsuValidationSchema({});
5+
6+
it('accepts first and last names with accented Latin letters', async () => {
7+
await expect(
8+
schema.validate({
9+
[ESU_FIELDS.FIRST_NAME]: 'André',
10+
[ESU_FIELDS.LAST_NAME]: 'François',
11+
[ESU_FIELDS.EMAIL]: 'andre.francois@example.com'
12+
})
13+
).resolves.toEqual({
14+
[ESU_FIELDS.FIRST_NAME]: 'André',
15+
[ESU_FIELDS.LAST_NAME]: 'François',
16+
[ESU_FIELDS.EMAIL]: 'andre.francois@example.com'
17+
});
18+
});
19+
});

0 commit comments

Comments
 (0)