Could this code be improved? Would you suggest more sophisticated way of doing client-side signup validation?
<!DOCTYPE html>
<html>
<head>
<script>
function validateForm() {
var name = document.forms["registrationForm"]["username"].value;
if (name == null || name == "") {
alert("Name must be filled out");
return false;
}
var password = document.forms["registrationForm"]["password"].value;
var repeatPassword = document.forms["registrationForm"]["passwordAgain"].value;
if (password.length < 8) {
alert("Password should contain 8 symbols or more");
return false;
}
if (password != repeatPassword) {
alert("Filled out passwords should match");
return false;
}
}
</script>
</head>
<body>
<h3>SignUp Form</h3>
<form name="registrationForm" onsubmit="return validateForm()" action="registration" method="post">
Email:<input type="text" name="username"/><br/><br/>
Password:<input type="password" name="password"/><br/><br/>
Repeat Password:<input type="password" name="passwordAgain"/><br/><br/>
<input type="submit" value="signup"/>
</form>
</body>
</html>
required
andminlength
attributes on<input>
. \$\endgroup\$