Sign Up Form Using Bootstrap with jQuery Validation

Sign Up Form Using Bootstrap with jQuery Validation

If you are looking for on how to create sign up form using bootstrap then you are at the right place. We all know using bootstrap is fabulous in term of designing and this is the front end framework of a website. Using bootstrap is for designing objective. In this tutorial, we are going to learn on how to create registration form using bootstrap with jQuery validation.

Sign Up Form

This is the form field where the user enters their information to signup and the classes of bootstrap.
  1. <div class="container">
  2.  
  3. <div class="wrapper">
  4.  
  5. <!-- form start -->
  6. <form method="post" role="form" id="register-form" autocomplete="off" action="submit.html">
  7.  
  8. <div class="header_style">
  9. <h3 class="title_style"><i class="fa fa-user"></i> Sign Up</h3>
  10.  
  11. <div class="pull-right">
  12. <h3 class="title_style"><span class="glyphicon glyphicon-pencil"></span></h3>
  13. </div>
  14.  
  15. </div>
  16.  
  17. <div class="body_style">
  18.  
  19. <div class="alert alert-info" id="message" style="display:none;">
  20. Successfully Registered!!!
  21. </div>
  22.  
  23. <div class="form-group">
  24. <div class="input-group">
  25. <div class="input-group-addon" style="border:1px solid blue;"><span class="glyphicon glyphicon-user"></span></div>
  26. <input name="name" type="text" class="form-control" autofocus="autofocus" placeholder="User Name ....." style="border:1px solid blue;">
  27. </div>
  28. <span class="help-block" id="error"></span>
  29. </div>
  30.  
  31. <div class="form-group">
  32. <div class="input-group">
  33. <div class="input-group-addon" style="border:1px solid blue;"><span class="glyphicon glyphicon-envelope"></span></div>
  34. <input name="email" type="text" class="form-control" placeholder="Email ....." style="border:1px solid blue;">
  35. </div>
  36. <span class="help-block" id="error"></span>
  37. </div>
  38.  
  39. <div class="row">
  40.  
  41. <div class="form-group col-lg-6">
  42. <div class="input-group">
  43. <div class="input-group-addon" style="border:1px solid blue;"><span class="glyphicon glyphicon-lock"></span></div>
  44. <input name="password" id="password" type="password" class="form-control" placeholder="Password ....." style="border:1px solid blue;">
  45. </div>
  46. <span class="help-block" id="error"></span>
  47. </div>
  48.  
  49. <div class="form-group col-lg-6">
  50. <div class="input-group">
  51. <div class="input-group-addon" style="border:1px solid blue;"><span class="glyphicon glyphicon-lock"></span></div>
  52. <input name="cpassword" type="password" class="form-control" placeholder="Re-type Password ....." style="border:1px solid blue;">
  53. </div>
  54. <span class="help-block" id="error"></span>
  55. </div>
  56.  
  57. </div>
  58.  
  59.  
  60. </div>
  61.  
  62. <div class="footer_style">
  63. <button type="submit" class="btn btn-success" style="border:1px solid blue;">
  64. <span class="glyphicon glyphicon-ok"></span> Sign Up
  65. </button>
  66. </div>
  67.  
  68.  
  69. </form>
  70.  
  71. </div>
  72.  
  73. </div>
This is the result of the code above. Result

jQuery Validation

Here the links. Put this file before end of your BODY tag.
  1. <script src="bootstrap/js/bootstrap.min.js"></script>
  2. <script src="assets/jquery-1.11.2.min.js"></script>
  3. <script src="assets/jquery.validate.min.js"></script>
  4. <script src="assets/register.js"></script>
  1. $('document').ready(function()
  2. {
  3. // name validation
  4. var nameregex = /^[a-zA-Z ]+$/;
  5.  
  6. $.validator.addMethod("validname", function( value, element ) {
  7. return this.optional( element ) || nameregex.test( value );
  8. });
  9.  
  10. // valid email pattern
  11. var eregex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  12.  
  13. $.validator.addMethod("validemail", function( value, element ) {
  14. return this.optional( element ) || eregex.test( value );
  15. });
  16.  
  17. $("#register-form").validate({
  18.  
  19. rules:
  20. {
  21. name: {
  22. required: true,
  23. validname: true,
  24. minlength: 4
  25. },
  26. email: {
  27. required: true,
  28. validemail: true
  29. },
  30. password: {
  31. required: true,
  32. minlength: 8,
  33. maxlength: 15
  34. },
  35. cpassword: {
  36. required: true,
  37. equalTo: '#password'
  38. },
  39. },
  40. messages:
  41. {
  42. name: {
  43. required: "<b style='font-family:cursive; font-size:18px; color:red;'>Please Enter Correct User Name</b>",
  44. validname: "<b style='font-family:cursive; font-size:18px; color:red;'>Name must contain only alphabets and space</b>",
  45. minlength: "<b style='font-family:cursive; font-size:18px; color:red;'>Your Name is Too Short</b>"
  46. },
  47. email: {
  48. required: "<b style='font-family:cursive; font-size:18px; color:red;'>Please Enter Correct Email Address</b>",
  49. validemail: "<b style='font-family:cursive; font-size:18px; color:red;'>Enter Valid Email Address</b>"
  50. },
  51. password:{
  52. required: "<b style='font-family:cursive; font-size:18px; color:red;'>Please Enter Correct Password</b>",
  53. minlength: "<b style='font-family:cursive; font-size:18px; color:red;'>Password at least have 8 characters</b>"
  54. },
  55. cpassword:{
  56. required: "<b style='font-family:cursive; font-size:18px; color:red;'>Please Re-type Your Password</b>",
  57. equalTo: "<b style='font-family:cursive; font-size:18px; color:red;'>Password Did not Match !</b>"
  58. }
  59. },
  60. errorPlacement : function(error, element) {
  61. $(element).closest('.form-group').find('.help-block').html(error.html());
  62. },
  63. highlight : function(element) {
  64. $(element).closest('.form-group').removeClass('has-success').addClass('has-error');
  65. },
  66. unhighlight: function(element, errorClass, validClass) {
  67. $(element).closest('.form-group').removeClass('has-error').addClass('has-success');
  68. $(element).closest('.form-group').find('.help-block').html('');
  69. },
  70. }
This is the result after coding the jQUery Validation function. ResultResultAnd, this look like the result after all field is correct. Result And, that's it. This is the steps on how to create sign up form using bootstrap with jQuery validation. Kindly click the "Download Code" button below for full source code. Thank you very much. Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

Add new comment