diff --git a/yup/src/__tests__/__fixtures__/data.ts b/yup/src/__tests__/__fixtures__/data.ts index 9499b94a..a6a04aa0 100644 --- a/yup/src/__tests__/__fixtures__/data.ts +++ b/yup/src/__tests__/__fixtures__/data.ts @@ -5,8 +5,15 @@ export const schema = yup.object({ username: yup.string().matches(/^\w+$/).min(3).max(30).required(), password: yup .string() - .matches(/^[a-zA-Z0-9]{3,30}/) - .required(), + .matches(new RegExp('.*[A-Z].*'), 'One uppercase character') + .matches(new RegExp('.*[a-z].*'), 'One lowercase character') + .matches(new RegExp('.*\\d.*'), 'One number') + .matches( + new RegExp('.*[`~<>?,./!@#$%^&*()\\-_+="\'|{}\\[\\];:\\\\].*'), + 'One special character', + ) + .min(8, 'Must be at least 8 characters in length') + .required('New Password is required'), repeatPassword: yup.ref('password'), accessToken: yup.string(), birthYear: yup.number().min(1900).max(2013), @@ -23,8 +30,8 @@ export const schema = yup.object({ export const validData: yup.InferType = { username: 'Doe', - password: 'Password123', - repeatPassword: 'Password123', + password: 'Password123_', + repeatPassword: 'Password123_', birthYear: 2000, email: 'john@doe.com', tags: ['tag1', 'tag2'], diff --git a/yup/src/__tests__/__snapshots__/yup.ts.snap b/yup/src/__tests__/__snapshots__/yup.ts.snap index 2b44967a..012d39ab 100644 --- a/yup/src/__tests__/__snapshots__/yup.ts.snap +++ b/yup/src/__tests__/__snapshots__/yup.ts.snap @@ -23,7 +23,7 @@ Object { }, ], "password": Object { - "message": "password must match the following: \\"/^[a-zA-Z0-9]{3,30}/\\"", + "message": "One uppercase character", "ref": Object { "name": "password", }, @@ -64,7 +64,7 @@ Object { }, ], "password": Object { - "message": "password must match the following: \\"/^[a-zA-Z0-9]{3,30}/\\"", + "message": "One uppercase character", "ref": Object { "name": "password", }, @@ -114,13 +114,18 @@ Object { }, ], "password": Object { - "message": "password must match the following: \\"/^[a-zA-Z0-9]{3,30}/\\"", + "message": "One uppercase character", "ref": Object { "name": "password", }, "type": "matches", "types": Object { - "matches": "password must match the following: \\"/^[a-zA-Z0-9]{3,30}/\\"", + "matches": Array [ + "One uppercase character", + "One lowercase character", + "One number", + ], + "min": "Must be at least 8 characters in length", }, }, "username": Object { @@ -170,13 +175,18 @@ Object { }, ], "password": Object { - "message": "password must match the following: \\"/^[a-zA-Z0-9]{3,30}/\\"", + "message": "One uppercase character", "ref": Object { "name": "password", }, "type": "matches", "types": Object { - "matches": "password must match the following: \\"/^[a-zA-Z0-9]{3,30}/\\"", + "matches": Array [ + "One uppercase character", + "One lowercase character", + "One number", + ], + "min": "Must be at least 8 characters in length", }, }, "username": Object { diff --git a/yup/src/yup.ts b/yup/src/yup.ts index 65bd82c6..0de99d4e 100644 --- a/yup/src/yup.ts +++ b/yup/src/yup.ts @@ -17,12 +17,17 @@ const parseErrorSchema = ( } if (validateAllFieldCriteria) { + const types = previous[error.path!].types; + const messages = types && types[error.type!]; + previous[error.path!] = appendErrors( error.path!, validateAllFieldCriteria, previous, error.type!, - error.message, + messages + ? ([] as string[]).concat(messages as string[], error.message) + : error.message, ) as FieldError; }