login page in javascript with validation code example
Example 1: javascript login validation
<html>
<body>
<form id="form1" runat="server">
<div class="container">
<div class="main">
<h2>
Javascript Login Form Validation</h2>
<form id="form_id" method="post" name="myform">
<label>
User Name :</label>
<input type="text" name="username" id="username" />
<br><br>
<label>
Password :</label>
<input type="password" name="password" id="password" />
<input type="button" value="Login" id="submit" onclick="validate();" />
</form>
</div>
</div>
</form>
</html>
</body>
Example 2: html form validation
<form action="">
<label for="name">Username</label>
<input id="name" type="text" required />
<label for="Email">Email</label>
<!-- The required attribute will prompt the user to make sure -->
<!-- the fields are not empty, and that the email is formatted correctly -->
<!-- if you want to use custom validation you should use regex in JavaScript -->
<input id="Email" type="text" required />
</form>
Example 3: javascript login validation
<script language = "JavaScript">
function validate() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if (username == null || username == "") {
alert("Please enter the username.");
return false;
}
if (password == null || password == "") {
alert("Please enter the password.");
return false;
}
alert('Login successful');
}
</script>