Create a function that can be used as a validator for the password field of a user registration form. The validation function takes a string as an input and returns a validation result. The validation result should contain a boolean indicating if the password is valid or not, and also a field with the possible validation errors.
-
The password must be at least 8 characters long. If it is not met, then the following error message should be returned: “Password must be at least 8 characters”
-
The password must contain at least 2 numbers. If it is not met, then the following error message should be returned: “The password must contain at least 2 numbers”
-
The validation function should handle multiple validation errors.
For example, “somepas” should [show] an error message: “Password must be at least 8 characters\nThe password must contain at least 2 numbers”
-
The password must contain at least one capital letter. If it is not met, then the following error message should be returned: “password must contain at least one capital letter”
-
The password must contain at least one special character. If it is not met, then the following error message should be returned: “password must contain at least one special character”