Hello i am a beginner and started to learn Javascript…
i made a Userform with the help of Google but when i match ConfirmPassword to Password it does not match please show me where i am doing wrong in the below code:-
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Hello, world!</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>UserForm Validation with the help of Regular Expression</title>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script>
</head>
<body>
<h1 class="text-center bg-dark text-white">UserForm Registration with the help of Regular Expression</h1>
<div class="container">
<br>
<form onsubmit="return validation()">
<!-- Password -->
<div class="form-group">
<label>Password:</label>
<input type="text" name="" id="inputpassword" class="form-control" placeholder="Password">
<span id="spanpassword" class="text-danger font-weight-bold"></span>
</div>
<!-- ConfirmPassword -->
<div class="form-group">
<label>Confirm Password:</label>
<input type="text" name="" id="inputconfirmpassword" class="form-control"
placeholder="Confirm Password">
<span id="spanconfirmpassword" class="text-danger font-weight-bold"></span>
</div>
<!-- EmailAddress -->
<div class="form-group">
<label>Email Address:</label>
<input type="text" name="" id="inputemail" class="form-control" placeholder="Email">
<span id="spanemail" class="text-danger font-weight-bold"></span>
</div>
<br>
<!-- submit <button> -->
<input type="submit" name="" class="btn btn-primary">
</form>
</div>
<script type="text/JavaScript">
function validation(){
var password1 = document.getElementById("inputpassword").value;
var password2 = document.getElementById("inputconfirmpassword").value;
var email1 = document.getElementById("inputemail").value;
// Validate through RegularExpression
var passwordcheck1 =/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,15}$/;
var emailcheck = /^[A-Za-z_]{3,}@[A-Za-z]{3,}[.]{1}[A-Za-z.]{2,6}$/;
if (passwordcheck1.test(password1)){
document.getElementById("spanpassword").innerHTML="";
}
else{
document.getElementById("spanpassword").innerHTML="Invalid Password";
return false;
}
if(password1.match(password2)){
document.getElementById("spanconfirmpassword").innerHTML="No password matched";
}
else {
document.getElementById("spanconfirmpassword").innerHTML="Password matched";
return false;
}
if (emailcheck.test(email1)){
document.getElementById("spanemail").innerHTML="";
}
else{
document.getElementById("spanemail").innerHTML="Enter valid email address";
return false;
}
}
</script>
</body>
</html>```