group.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>BootstrapValidator demo</title>
  5. <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
  6. <link rel="stylesheet" href="../dist/css/bootstrapValidator.css"/>
  7. <script type="text/javascript" src="../vendor/jquery/jquery.min.js"></script>
  8. <script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
  9. <script type="text/javascript" src="../dist/js/bootstrapValidator.js"></script>
  10. </head>
  11. <body>
  12. <div class="container">
  13. <div class="row">
  14. <div class="col-lg-8 col-lg-offset-2">
  15. <div class="page-header">
  16. <h2>group option</h2>
  17. </div>
  18. <form id="form" method="post" class="form-horizontal" action="target.php">
  19. <div class="form-group">
  20. <div class="group">
  21. <label class="col-sm-2 control-label">First name</label>
  22. <div class="col-sm-4">
  23. <input type="text" class="form-control" name="firstName" />
  24. </div>
  25. </div>
  26. <div class="group">
  27. <label class="col-sm-2 control-label">Last name</label>
  28. <div class="col-sm-4">
  29. <input type="text" class="form-control" name="lastName" data-bv-group=".group" />
  30. </div>
  31. </div>
  32. </div>
  33. <div class="form-group">
  34. <label class="col-sm-2 control-label">Username</label>
  35. <div class="col-sm-5">
  36. <input type="text" class="form-control" name="username" />
  37. </div>
  38. </div>
  39. <div class="form-group">
  40. <label class="col-sm-2 control-label">Email address</label>
  41. <div class="col-sm-5">
  42. <input type="text" class="form-control" name="email" />
  43. </div>
  44. </div>
  45. <div class="form-group">
  46. <label class="col-sm-2 control-label">Password</label>
  47. <div class="col-sm-5">
  48. <input type="password" class="form-control" name="password" />
  49. </div>
  50. </div>
  51. <div class="form-group">
  52. <div class="col-sm-10 col-sm-offset-2">
  53. <button type="submit" class="btn btn-primary">Submit</button>
  54. </div>
  55. </div>
  56. </form>
  57. </div>
  58. </div>
  59. </div>
  60. <script type="text/javascript">
  61. $(document).ready(function() {
  62. $('#form').bootstrapValidator({
  63. message: 'This value is not valid',
  64. feedbackIcons: {
  65. valid: 'glyphicon glyphicon-ok',
  66. invalid: 'glyphicon glyphicon-remove',
  67. validating: 'glyphicon glyphicon-refresh'
  68. },
  69. //group: '.form-group',
  70. fields: {
  71. firstName: {
  72. group: '.group',
  73. validators: {
  74. notEmpty: {
  75. message: 'The first name is required and cannot be empty'
  76. }
  77. }
  78. },
  79. lastName: {
  80. // The "group" option can be set via HTML attribute
  81. // <input type="text" class="form-control" name="lastName" data-bv-group=".group" />
  82. validators: {
  83. notEmpty: {
  84. message: 'The last name is required and cannot be empty'
  85. }
  86. }
  87. },
  88. username: {
  89. message: 'The username is not valid',
  90. validators: {
  91. notEmpty: {
  92. message: 'The username is required and cannot be empty'
  93. },
  94. stringLength: {
  95. min: 6,
  96. max: 30,
  97. message: 'The username must be more than 6 and less than 30 characters long'
  98. },
  99. regexp: {
  100. regexp: /^[a-zA-Z0-9_\.]+$/,
  101. message: 'The username can only consist of alphabetical, number, dot and underscore'
  102. },
  103. different: {
  104. field: 'password',
  105. message: 'The username and password cannot be the same as each other'
  106. }
  107. }
  108. },
  109. email: {
  110. validators: {
  111. emailAddress: {
  112. message: 'The input is not a valid email address'
  113. }
  114. }
  115. },
  116. password: {
  117. validators: {
  118. notEmpty: {
  119. message: 'The password is required and cannot be empty'
  120. },
  121. identical: {
  122. field: 'confirmPassword',
  123. message: 'The password and its confirm are not the same'
  124. },
  125. different: {
  126. field: 'username',
  127. message: 'The password cannot be the same as username'
  128. }
  129. }
  130. }
  131. }
  132. });
  133. });
  134. </script>
  135. </body>
  136. </html>