RDX_RP
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Customer Registration</title>
<style>
body {
background-color: teal;
text-align: center;
font-family: Arial, sans-serif;
}
.registration-container {
background-color: Gray94;
color: black;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
max-width: 400px;
margin: 50px auto;
}
input, textarea {
width: 100%;
padding: 8px;
margin: 8px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
background-color: DodgerBlue;
color: white;
border: none;
padding: 10px 15px;
cursor: pointer;
width: 100%;
margin-top: 10px;
border-radius: 5px;
}
button:hover {
background-color: #0047ab; /* Cobalt color */
}
.success-message {
color: green;
margin-top: 20px;
}
.error-message {
color: red;
margin-top: 10px;
}
</style>
<script src="registration_script.js" defer></script>
</head>
<body>
<div class="registration-container">
<h2>Passenger Registration</h2>
<form id="registrationForm">
<input type="text" id="firstName" placeholder="First Name" maxlength="50" required>
<input type="text" id="lastName" placeholder="Last Name" maxlength="50" required>
<input type="date" id="dob" placeholder="Date of Birth" required>
<input type="email" id="email" placeholder="Email" required>
<textarea id="address" placeholder="Address (Street, City)" maxlength="100" required></textarea>
<input type="text" id="contactNumber" placeholder="Contact Number" maxlength="10" required>
<button type="submit">Register</button>
<button type="button" id="resetButton">Reset</button>
</form>
<p id="acknowledgment" class="success-message" style="display: none;"></p>
<p id="error-message" class="error-message"></p>
</div>
</body>
</html>
JAVASCRIPT
document.getElementById('registrationForm').addEventListener('submit', function(event) {
event.preventDefault(); // Prevent form submission
const firstName = document.getElementById('firstName').value.trim();
const dob = document.getElementById('dob').value;
const email = document.getElementById('email').value.trim();
const contactNumber = document.getElementById('contactNumber').value.trim();
const errorMessage = document.getElementById('error-message');
const acknowledgment = document.getElementById('acknowledgment');
errorMessage.textContent = ''; // Clear previous error message
acknowledgment.style.display = 'none'; // Hide acknowledgment message
// Validate Date of Birth
if (new Date(dob) <= new Date('1924-01-01')) {
errorMessage.textContent = 'Choose a date greater than 1/1/1924';
return;
}
// Validate Contact Number
if (!/^\d{10}$/.test(contactNumber)) {
errorMessage.textContent = 'Enter a valid contact number';
return;
}
// Validate Email
if (!/\S+@\S+\.\S+/.test(email)) {
errorMessage.textContent = 'Enter a valid mail id';
return;
}
// Generate Passenger ID and Password
const passengerId = 'PID' + Math.floor(Math.random() * 10000);
const password = firstName.substring(0, 4) + '@123';
acknowledgment.textContent = `Passenger Registration is successful. Passenger ID: ${passengerId}, Password: ${password}`;
acknowledgment.style.display = 'block';
});
document.getElementById('resetButton').addEventListener('click', function() {
if (confirm('Is it okay to reset the fields?')) {
document.getElementById('registrationForm').reset(); // Reset form fields
document.getElementById('error-message').textContent = ''; // Clear error messages
}
});