0% found this document useful (0 votes)
6 views

Name: Kaartika V.G Class and Sec: 3-C ROLL - NO: 50816 REG - NO: 2113141058116 Department: BSC Computer Science Topic: Client Side Validation

Class activity

Uploaded by

kaartikavg
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)
6 views

Name: Kaartika V.G Class and Sec: 3-C ROLL - NO: 50816 REG - NO: 2113141058116 Department: BSC Computer Science Topic: Client Side Validation

Class activity

Uploaded by

kaartikavg
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/ 6

NAME: KAARTIKA V.

CLASS AND SEC: 3-C

ROLL.NO: 50816

REG.NO: 2113141058116

DEPARTMENT: BSC COMPUTER SCIENCE

TOPIC: CLIENT SIDE VALIDATION


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Client-Side Validation with PHP</title>
<script>
function validateForm() {
// Retrieve form input values
var username =
document.getElementById('username').value;
var email = document.getElementById('email').value;
var password =
document.getElementById('password').value;

// Regular expressions for validation


var usernameRegex = /^[a-zA-Z0-9]+$/;
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
var passwordRegex = /^(?=.[A-Z])(?=.[a-
z])(?=.*\d).{8,}$/;
// Validation
if (!usernameRegex.test(username)) {
alert('Username must contain only alphanumeric
characters.');
return false;
}

if (!emailRegex.test(email)) {
alert('Invalid email format.');
return false;
}

if (!passwordRegex.test(password)) {
alert('Password must be at least 8 characters long
and include at least one uppercase letter, one lowercase
letter, and one digit.');
return false;
}

// If all validations pass, submit the form


return true;
}
</script>
</head>
<body>
<h2>Signup Form with Client-Side Validation</h2>

<!-- Simple form with input fields for username,


email, and password -->
<form method="post" action="process.php"
onsubmit="return validateForm();">
<label for="username">Username:</label>
<input type="text" name="username"
id="username" required><br>

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

<label for="password">Password:</label>
<input type="password" name="password"
id="password" required><br>

<button type="submit">Sign Up</button>


</form>

</body>
</html>
OUTPUT:

You might also like