CSS Practical No 08
CSS Practical No 08
<script>
function validateForm() {
// Clear previous errors
document.querySelectorAll('.error').forEach(function(error) {
error.style.display = 'none';
});
// Validate Name
let name = document.getElementById("name").value;
if (name === "") {
document.getElementById("nameError").style.display = 'inline';
isValid = false;
}
// Validate Email
let email = document.getElementById("email").value;
let emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
if (!emailPattern.test(email)) {
document.getElementById("emailError").style.display = 'inline';
isValid = false;
}
// Validate Password
let password = document.getElementById("password").value;
if (password.length < 6) {
document.getElementById("passwordError").style.display = 'inline';
isValid = false;
}
</body>
</html>
Output: