0% found this document useful (0 votes)
19 views15 pages

Web 8

The document contains two HTML code snippets for a signup form, each with a unique design and validation features. The first code includes an email input field with basic validation, while the second code adds a password field with more complex validation requirements. Both forms utilize JavaScript for real-time validation and error handling.

Uploaded by

techyinsider001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views15 pages

Web 8

The document contains two HTML code snippets for a signup form, each with a unique design and validation features. The first code includes an email input field with basic validation, while the second code adds a password field with more complex validation requirements. Both forms utilize JavaScript for real-time validation and error handling.

Uploaded by

techyinsider001
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

WEB ENGNIEERING

LAB REPORT 8

HITEC UNIVERSITY TAXILA CANTT

SUBMITTED BY:
HUSNAIN ALI (22-SE-026)
SUBMITTED TO:
MAM Amber Urooj
CODE 1:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Signup Form</title>
<style>
body {
font-family: Arial, sans-serif;
background: linear-gradient(135deg, #a18cd1, #fbc2eb); /* Unique gradient
background */
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
}

.form-container {
background-color: #ffffff;
padding: 30px 40px;
border-radius: 10px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 400px;
}

h2 {
text-align: center;
color: #333;
}

.form-group {
margin-bottom: 20px;
}

label {
display: block;
margin-bottom: 8px;
font-weight: bold;
}

input {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}

input.invalid {
border-color: red;
}

.error {
color: red;
font-size: 0.9em;
display: none;
}

button {
width: 100%;
padding: 12px;
background-color: #6a11cb;
color: white;
font-weight: bold;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}

button:hover {
background-color: #2575fc;
}
</style>
</head>
<body>

<div class="form-container">
<h2>Signup Form</h2>
<form id="signupForm" novalidate>
<div class="form-group">
<label for="email">Email:</label>
<input type="text" id="email" name="email" required>
<div class="error" id="emailError">Please enter a valid email address.</div>
</div>
<button type="submit">Sign Up</button>
</form>
</div>

<script>
const emailInput = document.getElementById('email');
const emailError = document.getElementById('emailError');

function validateEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}

emailInput.addEventListener('input', () => {
const email = emailInput.value;
if (!validateEmail(email)) {
emailInput.classList.add('invalid');
emailError.style.display = 'block';
} else {
emailInput.classList.remove('invalid');
emailError.style.display = 'none';
}
});

document.getElementById('signupForm').addEventListener('submit', function(e)
{
if (!validateEmail(emailInput.value)) {
e.preventDefault();
emailInput.classList.add('invalid');
emailError.style.display = 'block';
}
});
</script>

</body>
</html>

OutPut:

Code 2:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Signup Form</title>
<style>
body {
font-family: Arial, sans-serif;
background: linear-gradient(135deg, #89f7fe, #66a6ff); /* Unique background
*/
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
}

.form-container {
background-color: #ffffff;
padding: 30px 40px;
border-radius: 10px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 400px;
}

h2 {
text-align: center;
color: #333;
}

.form-group {
margin-bottom: 20px;
}

label {
display: block;
margin-bottom: 8px;
font-weight: bold;
}

input {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
input.invalid {
border-color: red;
}

.error {
color: red;
font-size: 0.9em;
display: none;
}

button {
width: 100%;
padding: 12px;
background-color: #007BFF;
color: white;
font-weight: bold;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
</style>
</head>
<body>

<div class="form-container">
<h2>Signup Form</h2>
<form id="signupForm" novalidate>
<div class="form-group">
<label for="email">Email:</label>
<input type="text" id="email" name="email" required>
<div class="error" id="emailError">Please enter a valid email address.</div>
</div>

<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<div class="error" id="passwordError">
Password must contain at least 1 uppercase, 1 lowercase, 1 digit, and 1
special character.
</div>
</div>
<button type="submit">Sign Up</button>
</form>
</div>

<script>
const emailInput = document.getElementById('email');
const emailError = document.getElementById('emailError');
const passwordInput = document.getElementById('password');
const passwordError = document.getElementById('passwordError');

function validateEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}

function validatePassword(password) {
const upper = /[A-Z]/;
const lower = /[a-z]/;
const digit = /[0-9]/;
const special = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?`~]/;

return upper.test(password) && lower.test(password) && digit.test(password)


&& special.test(password);
}

emailInput.addEventListener('input', () => {
if (!validateEmail(emailInput.value)) {
emailInput.classList.add('invalid');
emailError.style.display = 'block';
} else {
emailInput.classList.remove('invalid');
emailError.style.display = 'none';
}
});

passwordInput.addEventListener('input', () => {
if (!validatePassword(passwordInput.value)) {
passwordInput.classList.add('invalid');
passwordError.style.display = 'block';
} else {
passwordInput.classList.remove('invalid');
passwordError.style.display = 'none';
}
});

document.getElementById('signupForm').addEventListener('submit', function(e)
{
const emailValid = validateEmail(emailInput.value);
const passwordValid = validatePassword(passwordInput.value);

if (!emailValid || !passwordValid) {
e.preventDefault();
if (!emailValid) {
emailInput.classList.add('invalid');
emailError.style.display = 'block';
}
if (!passwordValid) {
passwordInput.classList.add('invalid');
passwordError.style.display = 'block';
}
}
});
</script>

</body>
</html>

OUTPUT:

You might also like