Validation with min length and byte validation in reset added

This commit is contained in:
Muhammed Sinan 2024-12-13 18:34:28 +05:30
parent 18193db7bf
commit 5d90c4b9e4
2 changed files with 14 additions and 8 deletions

View File

@ -29,10 +29,15 @@ const RESET_PASSWORD_SCHEMA = yup.object().shape({
defaultMessage: 'Password must be at least 8 characters',
values: { min: 8 },
})
.max(70,{
id: translatedErrors.maxLength.id,
defaultMessage: "Password should be less than 70 characters"
})
.test(
'required-byte-size',
'Password must be between 8 and 70 bytes',
(value) => {
if (!value) return false;
const byteSize = new TextEncoder().encode(value).length;
return byteSize >= 8 && byteSize <= 70;
}
)
.matches(/[a-z]/, {
message: {
id: 'components.Input.error.contain.lowercase',
@ -114,9 +119,9 @@ const ResetPassword = () => {
{isBaseQueryError(error)
? formatAPIError(error)
: formatMessage({
id: 'notification.error',
defaultMessage: 'An error occurred',
})}
id: 'notification.error',
defaultMessage: 'An error occurred',
})}
</Typography>
) : null}
</Column>

View File

@ -22,10 +22,11 @@ export const username = yup.string().min(1);
export const password = yup
.string()
.min(8)
.test(
'required-byte-size',
'Password must be between 8 and 70 bytes',
(value:string) => {
(value) => {
if (!value) return false;
const byteSize = new TextEncoder().encode(value).length;
return byteSize >= 8 && byteSize <= 70;