Registration Form Validation Using Javascript Example
Jun 10, 2021 . Admin
Hello Friends,
Now let's see example of how to use form validation in javascript. Here you will learn how to use javascript form validation. We will use how to form validation in javascript. This is a short guide on form validation. Let's get started with how to use form validation in javascript.
Here i will give you many example how you can use form validation in javascript.
Example :<html> <head> <title>Registration Form Validation Using Javascript Example - Mywebtuts.com</title> <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"> </head> <body> <div class="container mt-2"> <div class="row"> <div class="col-md-12"> <div class="card"> <div class="card-header"> <h3>Form Validation</h3> </div> <div class="card-body"> <form name="myForm" action="demo_form.asp" onsubmit="return validateForm();" method="post"> <div class="form-group"> <label>First Name :</label> <input id="firstname" name="firstname" type="text" class="form-control" placeholder="Enter FirstName"> </div> </div> <div class="form-group"> <label>Email Address :</label> <input id="email" name="email" type="email" class="form-control" placeholder="Enter email"> </div> <div class="form-group"> <label>Password :</label> <input id="password" name="password" type="password" class="form-control" placeholder="Password"> </div> <button type="submit" value="Submit" class="btn btn-primary">Submit</button> </form> </div> </div> </div> </div> </div> </body> <script type="text/javascript"> function validateForm() { var x=document.forms["myForm"]["firstname"].value; if (x==null || x=="") { alert("First Name must be filled out"); return false; } var a=document.forms["myForm"]["lastname"].value; if (a==null || a=="") { alert("Last Name must be filled out"); return false; } var b=document.forms["myForm"]["email"].value; if (b==null || b=="") { alert("Email must be filled out"); return false; } var y=document.forms["myForm"]["password"].value; if (y==null || y=="") { alert("Password name must be filled out"); return false; } } </script> </html>
It will help you...