Warning: preg_grep(): Compilation failed: quantifier does not follow a repeatable item at offset 146 in /var/www/tg-me/post.php on line 75
Библиотека фронтендера | Frontend, JS, JavaScript, React.js, Angular.js, Vue.js | Telegram Webview: frontendproglib/6267 -
Telegram Group & Telegram Channel
🌟 Как реализовать безопасный ввод с помощью валидации на стороне клиента

Валидация на стороне клиента — это первый шаг в обеспечении безопасности данных, вводимых пользователями, прежде чем они попадут на сервер.

Почему важно:

📍 Защищает от XSS и SQL-инъекций

📍 Предотвращает отправку некорректных данных

📍 Повышает UX за счет быстрой обратной связи

Как внедрить:

1. Делаем проверку на пустое поле:


const form = document.querySelector('form');
const input = document.querySelector('input[name="username"]');

form.addEventListener('submit', (event) => {
if (!input.value.trim()) {
event.preventDefault();
alert('Поле не может быть пустым!');
}
});


2. Проверяем корректность email:


const emailInput = document.querySelector('input[name="email"]');

form.addEventListener('submit', (event) => {
const email = emailInput.value;
const regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;

if (!regex.test(email)) {
event.preventDefault();
alert('Введите корректный email!');
}
});


3. Ограничиваем длину пароля:


const passwordInput = document.querySelector('input[name="password"]');

form.addEventListener('submit', (event) => {
if (passwordInput.value.length < 6) {
event.preventDefault();
alert('Пароль должен быть не менее 6 символов!');
}
});


4. Используем атрибуты HTML5 для валидации:


<form>
<input type="email" name="email" required>
<input type="password" name="password" minlength="6" required>
<button type="submit">Отправить</button>
</form>


5. Экранируем пользовательский ввод для защиты от XSS:


function escapeHtml(text) {
const element = document.createElement('div');
if (text) {
element.innerText = text;
element.textContent = text;
}
return element.innerHTML;
}

const userInput = '<script>alert("XSS")</script>';
const safeInput = escapeHtml(userInput);
console.log(safeInput);


💡 Применение этих методов поможет обезопасить вводимые данные и защитить приложение от популярных угроз.

🐸 Библиотека фронтендера

#буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/frontendproglib/6267
Create:
Last Update:

🌟 Как реализовать безопасный ввод с помощью валидации на стороне клиента

Валидация на стороне клиента — это первый шаг в обеспечении безопасности данных, вводимых пользователями, прежде чем они попадут на сервер.

Почему важно:

📍 Защищает от XSS и SQL-инъекций

📍 Предотвращает отправку некорректных данных

📍 Повышает UX за счет быстрой обратной связи

Как внедрить:

1. Делаем проверку на пустое поле:


const form = document.querySelector('form');
const input = document.querySelector('input[name="username"]');

form.addEventListener('submit', (event) => {
if (!input.value.trim()) {
event.preventDefault();
alert('Поле не может быть пустым!');
}
});


2. Проверяем корректность email:


const emailInput = document.querySelector('input[name="email"]');

form.addEventListener('submit', (event) => {
const email = emailInput.value;
const regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;

if (!regex.test(email)) {
event.preventDefault();
alert('Введите корректный email!');
}
});


3. Ограничиваем длину пароля:


const passwordInput = document.querySelector('input[name="password"]');

form.addEventListener('submit', (event) => {
if (passwordInput.value.length < 6) {
event.preventDefault();
alert('Пароль должен быть не менее 6 символов!');
}
});


4. Используем атрибуты HTML5 для валидации:


<form>
<input type="email" name="email" required>
<input type="password" name="password" minlength="6" required>
<button type="submit">Отправить</button>
</form>


5. Экранируем пользовательский ввод для защиты от XSS:


function escapeHtml(text) {
const element = document.createElement('div');
if (text) {
element.innerText = text;
element.textContent = text;
}
return element.innerHTML;
}

const userInput = '<script>alert("XSS")</script>';
const safeInput = escapeHtml(userInput);
console.log(safeInput);


💡 Применение этих методов поможет обезопасить вводимые данные и защитить приложение от популярных угроз.

🐸 Библиотека фронтендера

#буст

BY Библиотека фронтендера | Frontend, JS, JavaScript, React.js, Angular.js, Vue.js




Share with your friend now:
tg-me.com/frontendproglib/6267

View MORE
Open in Telegram


Библиотека фронтендера | Frontend JS JavaScript React js Angular js Vue js Telegram | DID YOU KNOW?

Date: |

Unlimited members in Telegram group now

Telegram has made it easier for its users to communicate, as it has introduced a feature that allows more than 200,000 users in a group chat. However, if the users in a group chat move past 200,000, it changes into "Broadcast Group", but the feature comes with a restriction. Groups with close to 200k members can be converted to a Broadcast Group that allows unlimited members. Only admins can post in Broadcast Groups, but everyone can read along and participate in group Voice Chats," Telegram added.

Telegram Gives Up On Crypto Blockchain Project

Durov said on his Telegram channel today that the two and a half year blockchain and crypto project has been put to sleep. Ironically, after leaving Russia because the government wanted his encryption keys to his social media firm, Durov’s cryptocurrency idea lost steam because of a U.S. court. “The technology we created allowed for an open, free, decentralized exchange of value and ideas. TON had the potential to revolutionize how people store and transfer funds and information,” he wrote on his channel. “Unfortunately, a U.S. court stopped TON from happening.”

Библиотека фронтендера | Frontend JS JavaScript React js Angular js Vue js from us


Telegram Библиотека фронтендера | Frontend, JS, JavaScript, React.js, Angular.js, Vue.js
FROM USA