Tehnologii Web/2022-2023/Laborator 5

Introduction
In this laboratory, we will implement a sign up page with custom validation.


 * You should create a separate HTML page.
 * You should use the already existing CSS styles from previous lab work.
 * We are going to use Typescript, so the script extension should be .ts
 * Parcel has built-in support for Typescript, so changing the extension should be enough.
 * Typescript is a superset of Javascript. Every piece of code written in Javascript can be understood by Typescript.
 * Typescript has additional checks. So, if you have certain errors in your code that weren't triggered in Javascript, then you should adapt the code for Typescript.
 * Browsers don't support Typescript as a standard. So, your workflow must contain a Typescript compiler.

The Requirements

 * First name and last name must have minimum 2 characters each.
 * First name and last name together must have at least 6 characters (with no white-spaces).
 * The email address must valid.
 * User must be at least 14 years old.
 * The password must have at least 8 characters, minimum 1 lowercase, 1 uppercase, 1 digit, and 1 special character !@#$%^?><;'\&*.
 * Passwords must match.



Step 1
Add the HTML elements in your page. Add the appropriate CSS styles.

Step 2
In your .ts file add the following Form Data interface.

Make sure if you are using Parcel to change the .js to .ts extension.

Other bundlers won't necessarily allow to include .ts files directly in your HTML page. Step 3

Define your first Typescript type. In this case, FormField type will be a string, but a string that represents a key of IFormData interface.

Step 4
Create a Typescript class.

formData is a normal field of an instance, fields is static.

Create an instance of our class.

Step 5
Add a constructor. We want to update the form data on every input event.

'''Add the following code snippet. Watch the browser console to see how formData is being updated in real time.'''

Note


 * using ! would force to bypass the null checks. getElementById can return null.
 * using ! operator is generally a bad practice in Typescript, but in our case, our fields are statically defined and they reflect the ids of the elements.
 * {...object} spread operator would make a clone (flat-clone) of the object.
 * [field] snipped will patch the object in that particular key.

Step 6
Add the following validation in onDataChanged method.

The first one was done as an example.

Complete the rest of the validation requirements.

Note


 * == and === have a special meaning in Typescript.
 * You might split the implementation in several methods.