diff --git a/src/features/Register/components/RegistrationStep/hooks/useValidateForm.tsx b/src/features/Register/components/RegistrationStep/hooks/useValidateForm.tsx index 47ff9628..e3fff184 100644 --- a/src/features/Register/components/RegistrationStep/hooks/useValidateForm.tsx +++ b/src/features/Register/components/RegistrationStep/hooks/useValidateForm.tsx @@ -46,21 +46,22 @@ export const useValidateForm = () => { setErrorOnEmptyFields(requiredFields, '') return false } + hasError = setErrorOnEmptyFields(simpleValidationFields, 'error_fill_out_this_field') if (isFieldEmpty(formIds.email)) { updateFormError(formIds.email, 'error_empty_email') hasError = true } else if (!isValidEmail(email)) { updateFormError(formIds.email, 'error_invalid_email_format') + hasError = true } if (!isValidPassword(password)) { updateFormError(formIds.password, 'error_simple_password') hasError = true } - if (isValidPhone(phone)) { + if (!isValidPhone(phone)) { updateFormError(formIds.phone, 'error_invalid_phone_format') hasError = true } - hasError = setErrorOnEmptyFields(simpleValidationFields, 'error_fill_out_this_field') return !hasError } diff --git a/src/features/Register/helpers/isValidPassword/__tests__/index.tsx b/src/features/Register/helpers/isValidPassword/__tests__/index.tsx index 17fb9953..1516a97a 100644 --- a/src/features/Register/helpers/isValidPassword/__tests__/index.tsx +++ b/src/features/Register/helpers/isValidPassword/__tests__/index.tsx @@ -1,6 +1,7 @@ import { isValidPassword } from '..' it('invalid passwords', () => { + expect(isValidPassword('')).toBeFalsy() expect(isValidPassword('a')).toBeFalsy() expect(isValidPassword('1')).toBeFalsy() expect(isValidPassword('abcdef')).toBeFalsy() @@ -12,4 +13,5 @@ it('invalid passwords', () => { it('valid passwords', () => { expect(isValidPassword('aASbc!def123$')).toBeTruthy() expect(isValidPassword('Abcdef@123$')).toBeTruthy() + expect(isValidPassword('Abcd1234')).toBeTruthy() }) diff --git a/src/features/Register/helpers/isValidPassword/index.tsx b/src/features/Register/helpers/isValidPassword/index.tsx index c8cdbec4..edbf69db 100644 --- a/src/features/Register/helpers/isValidPassword/index.tsx +++ b/src/features/Register/helpers/isValidPassword/index.tsx @@ -1,4 +1,4 @@ -export const passwordRegex = '^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,500}$' +export const passwordRegex = '^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).{8,500}$' const passwordRegExp = new RegExp(passwordRegex) @@ -6,7 +6,6 @@ const passwordRegExp = new RegExp(passwordRegex) * At least one upper case English letter, (?=.*?[A-Z]) * At least one lower case English letter, (?=.*?[a-z]) * At least one digit, (?=.*?[0-9]) - * At least one special character, (?=.*?[#?!@$%^&*-]) * Minimum eight in length .{8,} (with the anchors) */ export const isValidPassword = (password: string) => (