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', defaultMessage: 'Password must be at least 8 characters',
values: { min: 8 }, values: { min: 8 },
}) })
.max(70,{ .test(
id: translatedErrors.maxLength.id, 'required-byte-size',
defaultMessage: "Password should be less than 70 characters" '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]/, { .matches(/[a-z]/, {
message: { message: {
id: 'components.Input.error.contain.lowercase', id: 'components.Input.error.contain.lowercase',
@ -114,9 +119,9 @@ const ResetPassword = () => {
{isBaseQueryError(error) {isBaseQueryError(error)
? formatAPIError(error) ? formatAPIError(error)
: formatMessage({ : formatMessage({
id: 'notification.error', id: 'notification.error',
defaultMessage: 'An error occurred', defaultMessage: 'An error occurred',
})} })}
</Typography> </Typography>
) : null} ) : null}
</Column> </Column>

View File

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