diff --git a/src/screens/LoginPage/LoginPage.test.tsx b/src/screens/LoginPage/LoginPage.test.tsx index 3733a454dd..698c83d42e 100644 --- a/src/screens/LoginPage/LoginPage.test.tsx +++ b/src/screens/LoginPage/LoginPage.test.tsx @@ -50,8 +50,8 @@ const MOCKS = [ request: { query: SIGNUP_MUTATION, variables: { - firstName: 'John', - lastName: 'Doe', + firstName: 'John Patrick ', + lastName: 'Doe ', email: 'johndoe@gmail.com', password: 'johnDoe', }, diff --git a/src/screens/LoginPage/LoginPage.tsx b/src/screens/LoginPage/LoginPage.tsx index 2ed1e71c13..7703266afa 100644 --- a/src/screens/LoginPage/LoginPage.tsx +++ b/src/screens/LoginPage/LoginPage.tsx @@ -176,7 +176,7 @@ const loginPage = (): JSX.Element => { }); return data.recaptcha; - } catch (error) { + } catch { /* istanbul ignore next */ toast.error(t('captchaError') as string); } @@ -204,8 +204,11 @@ const loginPage = (): JSX.Element => { toast.error(t('Please_check_the_captcha') as string); return; } - const isValidatedString = (value: string): boolean => - /^[a-zA-Z]+$/.test(value); + + const isValidName = (value: string): boolean => { + // Allow letters, spaces, and hyphens, but not consecutive spaces or hyphens + return /^[a-zA-Z]+(?:[-\s][a-zA-Z]+)*$/.test(value.trim()); + }; const validatePassword = (password: string): boolean => { const lengthCheck = new RegExp('^.{6,}$'); @@ -219,10 +222,10 @@ const loginPage = (): JSX.Element => { }; if ( - isValidatedString(signfirstName) && - isValidatedString(signlastName) && - signfirstName.length > 1 && - signlastName.length > 1 && + isValidName(signfirstName) && + isValidName(signlastName) && + signfirstName.trim().length > 1 && + signlastName.trim().length > 1 && signEmail.length >= 8 && signPassword.length > 1 && validatePassword(signPassword) @@ -264,10 +267,10 @@ const loginPage = (): JSX.Element => { toast.warn(t('passwordMismatches') as string); } } else { - if (!isValidatedString(signfirstName)) { + if (!isValidName(signfirstName)) { toast.warn(t('firstName_invalid') as string); } - if (!isValidatedString(signlastName)) { + if (!isValidName(signlastName)) { toast.warn(t('lastName_invalid') as string); } if (!validatePassword(signPassword)) {