Created
July 1, 2025 20:00
-
-
Save SomeNiceCode/624f14f9c9737b4993879d852c32f7f6 to your computer and use it in GitHub Desktop.
Forms Validation JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.getElementById("registrationForm").addEventListener("submit", function (e) { | |
e.preventDefault(); | |
const email = document.getElementById("email").value.trim(); | |
const username = document.getElementById("username").value.trim(); | |
const password = document.getElementById("password").value; | |
const errorMsg = document.getElementById("errorMsg"); | |
errorMsg.textContent = ""; | |
if (!email.includes("@")) { | |
errorMsg.textContent = "Введите корректный email."; | |
return; | |
} | |
if (username.length < 3) { | |
errorMsg.textContent = "Логин должен содержать минимум 3 символа."; | |
return; | |
} | |
if (password.length < 6) { | |
errorMsg.textContent = "Пароль должен быть не менее 6 символов."; | |
return; | |
} | |
alert("Форма успешно отправлена!"); | |
//можно отправить данные на сервер | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment