For this exercise, you will have to implement an **error type**.
For this exercise, you will have to implement an **error type** for a form validator. This must validate the password and the first name.
The main objective is to create a form validator, where you must implement an
The first name must not be empty and the password must have **at least 8 characters**, and a combination of **alphabetic**, **numeric** and **none-alphanumeric** (`<`, `&`, `/` ...).
error type. This must validate the password and the first name. The
first name must not be empty and the password must have **at least 8 char**, a **combination of alphanumeric**, **none-alphanumeric** (ex: <, & or /, ...)
ex: "asDd123=%" => good (as 8 char, alphanumeric and non-alphanumeric)\
examples
"asgfD" => error (does only have alphabetic letters)\
- `"asDd123=%"`: **good**.
"asdsdf2" => error (missing none-alphanumeric)\
- `"asgfD"`: **error** as it only contains alphabetic characters.
"sad\_#$" => error (does not have a combination of alphanumeric)
- `"asdsdf2"`: **error** as it is missing none-alphanumeric characters.
- `"sad\_#$"`: **error** as it is missing numeric characters.
Create a structure called `Form` that will have the following fields:
Create a structure named `Form` that will have the following fields:
- `first_name`, that will be a string
- `first_name`: `String`
- `last_name`, that will be a string
- `last_name`: `String`
- `birth`, of type`NaiveDate` that will convert a string "2015-09-05" to a date of that format
- `birth`:`NaiveDate` that will convert a string `"2015-09-05"` to a date of that format.
- `fav_colour`, of type Color that must be a`enum` with the fields `Red`, `Blue` and `Green`
- `fav_colour`: of type `Color` that must be an`enum` with the fields `Red`, `Blue` and `Green`
- `birth_location`, that will be a string
- `birth_location`: `String`
- `password`, that will be a string
- `password`: `String`
You must also implement for this structure a function to initialize the structure, `new` and a function called
You must implement the **associated functions**`new` and
`validate` that will validate the form
`validate` that will validate the form.
For the error type you must create a type struct called `FErr`, that will be the type for the error
For the error type you must create a `struct` named `FErr`. It must have the fields:
It must have the fields:
- `form_values`, this will be a tuple of strings that will save the value that the user inserted into the form
- `form_values`: this will be a tuple of strings representing the invalid input. For example: `("password", "asdaSD\_")` or `("first_name", "someone")`
ex: ("password", "asdaSD\_")
- `date`: that will have the date that the error occurred in the format `"2020-12-14 09:33:41"`
("first_name", "someone")
- `err`: the error description:
- `"No user name"`
- `date`, that will have the date that the error occurred in the format "2020-12-14 09:33:41"
- `"At least 8 characters"`
- `err`, that will have the error description:
- `"Combination of different ASCII character types (numbers, letters and none alphanumeric characters)"`
- "No user name"
- "At least 8 characters"
- "Combination of different ASCII character types (numbers, letters and none alphanumeric characters)"