-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop.js
More file actions
61 lines (53 loc) · 1.94 KB
/
Copy pathoop.js
File metadata and controls
61 lines (53 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// THESE JS FILES ARE ABLE TO EXECUTE EXACTLY SAME TASKS WITH DIFFERENT APPROACHES
// TASKS:
// 1-TAKE INPUTS WHICH ARE EMAIL AND PASSWORD
// 2-CHECK THAT EMAIL EMPTY OR NOT
// 3-CHECK THAT PASSWORD IS EMPTY OR NOT IF IT IS NOT EMPTY IT HAVE TO INCLUDE MORE THAN 5 CHARACTER
// 4- IF ALL THE CONDITIONS ARE SATISFIED CREATE THE USER AND LOG THEM
class Validator {
static required = 'required'
static minLength = 'minLength'
static validate(value, validatorType, min){
if(validatorType===this.required){
return( value === "" ? false : true);
}
if(validatorType===this.minLength){
return (value.length < min ? false : true);
}
}
}
class User {
constructor(email, password){
this.email = email
this.password = password
}
logUser(){
console.log(this)
}
}
class Form {
constructor(){
this.form = document.getElementById("inputs")
this.userEmail = document.getElementById("exampleInputEmail1")
this.userPassword = document.getElementById("exampleInputPassword1")
this.form.addEventListener("submit", this.createUser.bind(this))
}
createUser(event){
event.preventDefault();
const email = this.userEmail.value.trim()
const password = this.userPassword.value.trim()
console.log("email: " + email)
console.log("password: " + password.length)
console.log("email validation: " + Validator.validate(email,"required"))
console.log("password validation: " + Validator.validate(password, "minLength", 6))
if(Validator.validate(email,"required") && Validator.validate(password, "minLength", 6) ){
const user = new User(email,password)
user.logUser()
}else{
alert("Wrong password or email")
return;
}
}
}
//We need to call this class to bring it to life. We can think the classes as blueprints
new Form()