-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
77 lines (67 loc) · 2.3 KB
/
main.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const data = {
name: "",
age: 24,
mail: "[email protected]",
roles: ["user", "owner"],
isAdmin: true,
image: {
url: "url_address",
title: "some title",
size: 100
},
}
function validateEmail(mail) {
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(mail).toLowerCase());
}
function validImage(image) {
if (data.image && typeof data.image.url === 'string' &&
typeof data.image.title === 'string' &&
typeof data.image.size === 'number') {
return 'Image проверен';
} else {
return 'Вы не вставили Image или вставили её не правильно';
}
}
function validArray(arr) {
if (Array.isArray(arr)) {
let count = 0;
for (let i = 0; i < arr.length; i++) {
if (typeof arr[i] === 'string') {
count += 1;
}
}
if (count === arr.length) {
return 'Массив проверен';
} else {
return "Все элементы массива должны быть типа 'String'";
}
} else {
return 'Вы не ввели Массив или ввели его неправильно';
}
}
function validObject(data) {
if (typeof data.name === 'string') {
console.log('Имя проверено');
} else {
console.log('Вы не ввели Имя или ввели его неправильно');
}
if (typeof data.age === 'number') {
console.log('Возраст проверен');
} else {
console.log('Вы не ввели Возраст или ввели его неправильно');
}
if (validateEmail(data.mail)) {
console.log('Mail проверен');
} else {
console.log('Вы не ввели Mail или ввели его неправильно');
}
console.log(validArray(data.roles));
if (typeof data.isAdmin === 'boolean') {
console.log('Root проверен');
} else {
console.log('Вы не ввели Root или ввели его неправильно');
}
console.log(validImage(data.image));
}
validObject(data);