Untitled
unknown
plain_text
2 years ago
1.4 kB
10
Indexable
<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<h2>Registration Form</h2>
<form id="registrationForm" onsubmit="return validateForm()">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br>
<input type="submit" value="Register">
</form>
<script>
function validateForm() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var email = document.getElementById("email").value;
if (!/^\w+$/.test(username)) {
alert("Invalid username. It should contain only letters and numbers.");
return false;
}
if (password.length < 8) {
alert("Invalid password. It should be at least 8 characters long.");
return false;
}
if (!/^\S+@\S+\.\S+$/.test(email)) {
alert("Invalid email format.");
return false;
}
alert("Registration successful!");
return true;
}
</script>
</body>
</html>Editor is loading...