Skip to content

Филимоненков Владимир #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 28 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ const pageFoot =
</html>
`;

// Валидация двнных формы: emal, мобильный телефон, имя, дата рождения
// Остальные данные вводятся "по-шаблону", поэтому там ошибок не может быть
function validation (value)
{
// Дата рождения не должна быть больше системной даты
const sysdate = new Date();
const mydate = new Date(value.dateOfBirth);
if (mydate > sysdate)
return `<p class="error">Ошибка!!! Дата рождения не может быть больше сегодня</p>`;
// Имя должно соcтоять из букв
const NAME_REGEXP = /[A-Z\sА-Я]/i;
if (!NAME_REGEXP.test(value.name) || value.name.length < 3)
return `<p class="error">Ошибка!!! Имя должно состоять из букв и содержать не менее 3 символов</p>`;
// email
const EMAIL_REGEXP = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/iu;
if (!EMAIL_REGEXP.test(value.email))
return `<p class="error">Ошибка!!! Не верный формат email</p>`;
// мобильный телефон (содержит 10 цифр)
const PHONE_REGEXP = /^[2-9]\d{2}[2-9]\d{2}\d{4}$/;
if (!PHONE_REGEXP.test(value.phone.replace(/\D/g,"")))
return `<p class="error">Ошибка!!! Не верный формат номера мобильного телефона</p>`;
};

app.listen(port, (err) => {
if (err) {
return console.log('something bad happened', err);
Expand All @@ -39,10 +62,12 @@ app.use(express.urlencoded({ extended: true }));

app.post('/pets/orders', (request, response) => {
const reqBody = request.body;
const pageBody = constructPageBody(reqBody);

let pageBody = constructPageBody(reqBody);
// Валидация (если вернулась не пустая строка, то была ошбка ввода данных)
const valid = validation(reqBody);
if (valid) pageBody = valid;

console.log(request.body);

response.send(`${pageHead}${pageBody}${pageFoot}`);
});

79 changes: 77 additions & 2 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,84 @@
<body>
<main>
<h1>Найди себе друга!</h1>

<p> Мы найдем питомцев, которые могут стать Вашим маленьким другом.
Информация будет направлена на указанный Вами канал связи.
</p>
<form action="/pets/orders" method="POST">
<section>
<h2>Характеристики питомца</h2>
<table class="petTable">
<tr>
<th scope = "col">Животное</th>
<th scope = "col">Пол</th>
<th scope = "col">Цвет глаз</th>
<th scope = "col">Длина хвоста</th>
<th scope = "col">Дата рождения</th>
</tr>
<tr id="mf">
<td>
<select name="petType">
<option value="cat">Кошка</option>
<option value="dog">Собака</option>
<option value="tiger">Тигр</option>
</select>
</td>
<td>
<div><input type="radio" name="gender" value="boy" checked>Мальчик</div>
<div><input type="radio" name="gender" value="girl">Девочка</div>
<div><input type="radio" name="gender" value="none">Не важно</div>
</td>
<td>
<input type="color" name="eyeColor" value="#5798d4">
</td>
<td>
<input type="range" min="20" max="120" step="1" value="50" name="tailLength">
</td>
<td>
<input type="date" name="dateOfBirth" value="2021-07-22">
</td>
</tr>
</table>
<p style="text-align:center">
<input type="RESET" value = "По умолчанию">
</p>
</section>

<section>
<h2>Ваши контактные данные</h2>
<table class="contact">
<tr>
<td>
<label>Имя
<input type="text" name="name" placeholder="Введите имя">
</label>
</td>
<td>
<label>E-mail
<input type="email" name="email" placeholder="[email protected]">
</label>
</td>
<td>
<label>Моб. телефон
<input type="tel" name="phone" required placeholder="(999)999-99-99">
</label>
</td>
</tr>
</table>
</section>
<p>
<q>Ты навсегда в ответе за всех, кого приручил</q>
[Антуан де Сент-Экзюпери <q>Маленький принц</q>]
</p>
<p>
<input type="checkbox" name="rules" value="true" checked required>
Я согласен с условиями и правилами
</p>
<p><input type="submit" name = "pet" value = "Отправить"></p>


<!--Форму размещай тут-->

</form>
</main>
</body>
</html>
32 changes: 31 additions & 1 deletion static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,37 @@ h1 {
margin-top: 0;
font-size: 50px;
text-align: center;
color: rgba(173,38,164,0.67);
color: rgba(100,38,100,0.67);
}

h2 {
font-family: "Segoe UI Light", "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 200;
margin-top: 0;
font-size: 25px;
color: rgba(100,38,100,0.67);
}

table {
width: 100%;
}

th {
text-align: left;
}

#mf {background-color: white;}
tr:nth-child(even) { background-color: rgba(100,38,100,0.2); }

p {
text-align:center;
}

section {
margin: 10px 0;
border: 3px dotted #ddd;
padding: 10px;
font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.error {
Expand Down