0% found this document useful (0 votes)
9 views3 pages

Assessment 322

assessment

Uploaded by

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

Assessment 322

assessment

Uploaded by

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

2 a)// Define a 2D array to represent the table

var table = [

["cell1", "cell2", "cell3"],

["cell4", "cell5", "cell6"],

["cell7", "cell8", "cell9"]

];

// Function to update cell contents

function updateCell(row, column, content) {

// Check if the row and column numbers are valid

if (row >= 0 && row < table.length && column >= 0 && column < table[row].length) {

// Update the cell's content

table[row][column] = content;

console.log("Cell (" + row + "," + column + ") updated to: " + content);

} else {

console.log("Invalid row or column number.");

// Example usage:

updateCell(0, 1, "New Value");

2 b) <!DOCTYPE html>

<html>

<head>

<title>Form Validation</title>

</head>

<body>

<h2>User Registration</h2>

<form id="registrationForm">
<label for="username">Username:</label>

<input type="text" id="username" required><br><br>

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

<input type="text" id="phoneNumber" required pattern="\+\d{2}\d{8}"><br><br>

<label for="password">Password:</label>

<input type="password" id="password" required><br><br>

<label for="confirmPassword">Confirm Password:</label>

<input type="password" id="confirmPassword" required><br><br>

<button type="button" onclick="validateForm()">Register</button>

</form>

<script>

function validateForm() {

var username = document.getElementById("username").value;

var phoneNumber = document.getElementById("phoneNumber").value;

var password = document.getElementById("password").value;

var confirmPassword = document.getElementById("confirmPassword").value;

// Regular expression to validate password: 1 uppercase letter, 2 special characters, and 5 digits or
lowercase letters

var passwordRegex = /^(?=.*[A-Z])(?=.*[!@#$%^&*()_+}{:;"'?/><.,])(?=.*[0-9a-z]){8}$/;

if (!passwordRegex.test(password)) {

alert("Password must contain at least 1 uppercase letter, 2 special characters, and 5 digits or
lowercase letters.");

return;

}
if (password !== confirmPassword) {

alert("Passwords do not match.");

return;

// Generate random password

var generatedPassword = generatePassword();

// Display the generated password

alert("Generated Password: " + generatedPassword);

// Optional: You can submit the form here if all validations pass

// document.getElementById("registrationForm").submit();

// Function to generate a random password

function generatePassword() {

var charset =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+";

var password = "";

for (var i = 0; i < 8; i++) {

password += charset.charAt(Math.floor(Math.random() * charset.length));

return password;

</script>

</body>

</html>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy