Vous êtes sur la page 1sur 12

<!

DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Corona Patient Details Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
}

.container {
max-width: 600px;
margin: 50px auto;
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}

h1 {
text-align: center;
margin-bottom: 20px;
}

label {
display: block;
margin-bottom: 5px;
}

input[type="text"],
select {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}

input[type="submit"] {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}

input[type="submit"]:hover {
background-color: #45a049;
}

.error {
color: red;
}
</style>
</head>
<body>
<div class="container">
<h1>Corona Patient Details Form</h1>
<form id="coronaForm">
<label for="patientName">Patient Name:</label>
<input type="text" id="patientName" name="patientName" required>

<label for="email">Email:</label>
<input type="text" id="email" name="email" required>

<label for="phoneNumber">Phone Number:</label>


<input type="text" id="phoneNumber" name="phoneNumber"
pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required>

<label for="requiredItems">Required Items:</label>


<select id="requiredItems" name="requiredItems" multiple>
<option value="mask">Mask</option>
<option value="sanitizer">Sanitizer</option>
<option value="gloves">Gloves</option>
</select>

<label for="patientMessage">Patient Message:</label>


<textarea id="patientMessage" name="patientMessage"></textarea>

<input type="submit" value="Submit">


</form>
<div id="validationMessage" class="error"></div>
<div id="output"></div>
</div>

<script>
const form = document.getElementById('coronaForm');
const validationMessage =
document.getElementById('validationMessage');
const output = document.getElementById('output');

form.addEventListener('submit', function(event) {
event.preventDefault();

const patientName = document.getElementById('patientName').value;


const email = document.getElementById('email').value;
const phoneNumber = document.getElementById('phoneNumber').value;
const patientMessage =
document.getElementById('patientMessage').value;
const requiredItems =
document.getElementById('requiredItems').selectedOptions;

// Validation
const emailRegex = /^[^\s@]+@[^\s@]+\.(com|gov|in)$/;
const phoneNumberRegex = /^\d{3}-\d{3}-\d{4}$/;
let isValid = true;

if (!emailRegex.test(email)) {
displayError('Email must end with .com, .gov, or .in');
isValid = false;
}

if (!phoneNumberRegex.test(phoneNumber)) {
displayError('Invalid Phone Number. Format should be XXX-XXX-
XXXX');
isValid = false;
}

if (isValid) {
validationMessage.textContent = '';
const selectedItems = Array.from(requiredItems).map(option =>
option.value).join(', ');

output.innerHTML = `
<p>Patient Name: ${patientName}</p>
<p>Email: ${email}</p>
<p>Phone Number: ${phoneNumber}</p>
<p>Required Items: ${selectedItems}</p>
<p>Patient Message: ${patientMessage}</p>
<p>Information about CORONA: $
{checkForCoronaKeywords(patientMessage)}</p>
<p>Submission Time: ${new Date().toLocaleString()}</p>
`;
}
});

function displayError(message) {
validationMessage.textContent = message;
}

function checkForCoronaKeywords(message) {
const keywords = ['COVID19', 'COVID', 'corona', 'coronavirus'];
const regex = new RegExp(keywords.join('|'), 'gi');
const matches = message.match(regex);
return matches ? 'Information about CORONA' : 'No information
about CORONA found';
}
</script>
</body>
</html>
2.
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Event Registration Form</title>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-


ui.min.css">

<style>

body {

font-family: Arial, sans-serif;

background-color: #f2f2f2;

margin: 0;

padding: 0;

.container {

max-width: 600px;

margin: 50px auto;

background-color: #fff;

padding: 20px;

border-radius: 10px;

box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);

h1 {

text-align: center;

margin-bottom: 20px;

label {
display: block;

margin-bottom: 5px;

input[type="text"],

select {

width: 100%;

padding: 10px;

margin-bottom: 15px;

border: 1px solid #ccc;

border-radius: 5px;

box-sizing: border-box;

input[type="submit"] {

background-color: #4CAF50;

color: white;

padding: 10px 20px;

border: none;

border-radius: 5px;

cursor: pointer;

font-size: 16px;

input[type="submit"]:hover {

background-color: #45a049;

.error {

color: red;

}
</style>

</head>

<body>

<div class="container">

<h1>Event Registration Form</h1>

<form id="registrationForm">

<label for="firstName">First Name (VIT Reg No):</label>

<input type="text" id="firstName" name="firstName" required>

<label for="lastName">Last Name:</label>

<input type="text" id="lastName" name="lastName" required>

<label for="city">City:</label>

<input type="text" id="city" name="city" autocomplete="on" required>

<label for="zipCode">Zip Code:</label>

<input type="text" id="zipCode" name="zipCode" pattern="\d{2}[-\s]\d{4}" required>

<label for="email">Email:</label>

<input type="email" id="email" name="email" required>

<label for="state">State:</label>

<select id="state" name="state">

<option value="Tamil Nadu">Tamil Nadu</option>

<option value="Karnataka">Karnataka</option>

<option value="Andhra Pradesh">Andhra Pradesh</option>

<option value="Kerala">Kerala</option>

</select>

<label for="speak">Are you speaking at the conference?</label>

<select id="speak" name="speak">


<option value="Yes">Yes</option>

<option value="No" selected>No</option>

</select>

<label for="pass">Conference Pass:</label>

<select id="pass" name="pass">

<option value="Regular">Regular</option>

<option value="VIP">VIP</option>

</select>

<label for="meal">Meal Preferences:</label>

<select id="meal" name="meal">

<option value="Vegetarian">Vegetarian</option>

<option value="Non-Vegetarian">Non-Vegetarian</option>

</select>

<input type="submit" value="Submit">

</form>

<div id="validationMessage" class="error"></div>

<div id="output"></div>

</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

<script>

$(function() {

var cities = ["Vellore", "Chennai", "Bangalore", "Hyderabad", "Mumbai", "Delhi"];

$("#city").autocomplete({

source: cities

});

});
$('#registrationForm').submit(function(event) {

event.preventDefault();

const firstName = $('#firstName').val();

const lastName = $('#lastName').val();

const zipCode = $('#zipCode').val();

const email = $('#email').val();

const state = $('#state').val();

const speak = $('#speak').val();

const pass = $('#pass').val();

const meal = $('#meal').val();

// Validation

const regNoRegex = /^[2][0-3]MIS\d{4}$/;

const emailRegex = /^[\w-\.]+@(vitstudent\.ac\.in|vit\.ac\.in)$/;

const zipCodeRegex = /^\d{2}[-\s]\d{4}$/;

if (!regNoRegex.test(firstName)) {

displayError('First name should be VIT student reg.no of 20, 21, 22, and 23 batch students
of MTech SE.');

return;

if (lastName.length < 3 || lastName.length > 35) {

displayError('Last name should be between 3 and 35 characters long.');

return;

if (!zipCodeRegex.test(zipCode)) {

displayError('Zip code should be exactly six digits with state code followed by one space or
hyphen, then postal code with 4 digits. Example: 63-2043 or 63 2043');

return;
}

if (!emailRegex.test(email)) {

displayError('Accept only vitstudent.ac.in or vit.ac.in email id.');

return;

validationMessage.textContent = '';

output.innerHTML = `

<p>First Name: ${firstName}</p>

<p>Last Name: ${lastName}</p>

<p>City: ${city}</p>

<p>Zip Code: ${zipCode}</p>

<p>Email: ${email}</p>

<p>State: ${state}</p>

<p>Speaking at the conference: ${speak}</p>

<p>Conference Pass: ${pass}</p>

<p>Meal Preferences: ${meal}</p>

`;

});

function displayError(message) {

$('#validationMessage').text(message);

</script>

</body>

</html>

Vous aimerez peut-être aussi