<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="bootstrap/css/bootstrap.css"> <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"> </head> <body> <div class="container"> <h1> Responsive Form Validation</h1> <form class="form-group" id="userForm" method="post" action=""> <legend>          Please Fill In The Following Details</legend> <p> <label for="name">Name :</label> <input id="name" class="form-control" name="name" type="text" placeholder="Name" > </p> <p> <label for="email">E-Mail Address :</label> <input id="email" class="form-control" type="email" name="email" placeholder="E-Mail Address" > </p> <p> <label for="phone">Phone Number :</label> <input id="phone" class="form-control" type="phone" name="phone" placeholder="Phone Number" > </p> <p> <label for="username">Username :</label> <input id="username" class="form-control" name="username" type="text" placeholder="Username" > </p> <p> <label for="password">Password :</label> <input id="password" class="form-control" name="password" type="password" placeholder="Password" > </p> <p> <label for="confirm_password">Confirm Password :</label> <input id="confirm_password" class="form-control" name="confirm_password" type="password" placeholder="Confirm Password" > </p> <p> <label for="agree">By Clicking Sign Up button, you agree to our Terms and Agreement.</label> <input type="checkbox" class="checkbox" id="agree" name="agree"> </p> <p> <input class="btn btn-primary" type="submit" value="Submit"> </p> </form> </div> </body> </html>
<script> $.validator.setDefaults({ submitHandler: function() { alert("submitted!"); } }); $(document).ready(function() { $("#userForm").validate({ rules: { name: "required", email: { required: true, email: true }, phone: { required: true, number: true }, username: { required: true, minlength: 6 }, password: { required: true, minlength: 6 }, confirm_password: { required: true, minlength: 6, equalTo: "#password" }, agree: "required" }, messages: { name: "Please Fill Up Your Name", email: "Please Enter a Valid Email Address", phone: { required: "Please Enter Your Phone Number", number: "Please Enter Only Numeric Value" }, username: { required: "Please Enter a Username", minlength: "Your Username Must Consist of at Least 6 Characters" }, password: { required: "Please Provide a Password", minlength: "Your Password Must Be at Least 6 Characters Long" }, confirm_password: { required: "Please Provide a Password", minlength: "Your Password Must Be at Least 6 Characters Long", equalTo: "Please Enter The Same Password As Above" }, agree: "Please Accept Policy & Agreement" } }); }); </script>