index.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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-1.10.2.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. <!-- form: -->
  15. <section>
  16. <div class="col-lg-8 col-lg-offset-2">
  17. <div class="page-header">
  18. <h2>Sign up</h2>
  19. </div>
  20. <form id="defaultForm" method="post" class="form-horizontal">
  21. <div class="form-group">
  22. <label class="col-lg-3 control-label">Username</label>
  23. <div class="col-lg-5">
  24. <input type="text" class="form-control" name="username" />
  25. </div>
  26. </div>
  27. <div class="form-group">
  28. <label class="col-lg-3 control-label">Email address</label>
  29. <div class="col-lg-5">
  30. <input type="text" class="form-control" name="email" />
  31. </div>
  32. </div>
  33. <div class="form-group">
  34. <label class="col-lg-3 control-label">Password</label>
  35. <div class="col-lg-5">
  36. <input type="password" class="form-control" name="password" />
  37. </div>
  38. </div>
  39. <div class="form-group">
  40. <label class="col-lg-3 control-label">Retype password</label>
  41. <div class="col-lg-5">
  42. <input type="password" class="form-control" name="confirmPassword" />
  43. </div>
  44. </div>
  45. <div class="form-group">
  46. <label class="col-lg-3 control-label">Gender</label>
  47. <div class="col-lg-9">
  48. <div class="radio">
  49. <label>
  50. <input type="radio" name="gender" value="male" /> Male
  51. </label>
  52. </div>
  53. <div class="radio">
  54. <label>
  55. <input type="radio" name="gender" value="female" /> Female
  56. </label>
  57. </div>
  58. <div class="radio">
  59. <label>
  60. <input type="radio" name="gender" value="other" /> Other
  61. </label>
  62. </div>
  63. </div>
  64. </div>
  65. <div class="form-group">
  66. <label class="col-lg-3 control-label">Languages</label>
  67. <div class="col-lg-9">
  68. <div class="checkbox">
  69. <label>
  70. <input type="checkbox" name="languages[]" value="english" /> English
  71. </label>
  72. </div>
  73. <div class="checkbox">
  74. <label>
  75. <input type="checkbox" name="languages[]" value="french" /> French
  76. </label>
  77. </div>
  78. <div class="checkbox">
  79. <label>
  80. <input type="checkbox" name="languages[]" value="german" /> German
  81. </label>
  82. </div>
  83. <div class="checkbox">
  84. <label>
  85. <input type="checkbox" name="languages[]" value="russian" /> Russian
  86. </label>
  87. </div>
  88. <div class="checkbox">
  89. <label>
  90. <input type="checkbox" name="languages[]" value="other" /> Other
  91. </label>
  92. </div>
  93. </div>
  94. </div>
  95. <div class="form-group">
  96. <label class="col-lg-3 control-label" id="captchaOperation"></label>
  97. <div class="col-lg-2">
  98. <input type="text" class="form-control" name="captcha" />
  99. </div>
  100. </div>
  101. <div class="form-group">
  102. <div class="col-lg-9 col-lg-offset-3">
  103. <button type="submit" class="btn btn-primary">Sign up</button>
  104. </div>
  105. </div>
  106. </form>
  107. </div>
  108. </section>
  109. <!-- :form -->
  110. </div>
  111. </div>
  112. <script type="text/javascript">
  113. $(document).ready(function() {
  114. // Generate a simple captcha
  115. function randomNumber(min, max) {
  116. return Math.floor(Math.random() * (max - min + 1) + min);
  117. };
  118. $('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));
  119. $('#defaultForm').bootstrapValidator({
  120. // live: 'submitted',
  121. message: 'This value is not valid',
  122. fields: {
  123. username: {
  124. message: 'The username is not valid',
  125. validators: {
  126. notEmpty: {
  127. message: 'The username is required and can\'t be empty'
  128. },
  129. // stringLength: {
  130. // min: 6,
  131. // max: 30,
  132. // message: 'The username must be more than 6 and less than 30 characters long'
  133. // },
  134. // regexp: {
  135. // regexp: /^[a-zA-Z0-9_\.]+$/,
  136. // message: 'The username can only consist of alphabetical, number, dot and underscore'
  137. // },
  138. remote: {
  139. url: 'remote.php',
  140. message: 'The username is not available'
  141. },
  142. // different: {
  143. // field: 'password',
  144. // message: 'The username and password can\'t be the same as each other'
  145. // }
  146. }
  147. },
  148. email: {
  149. validators: {
  150. emailAddress: {
  151. message: 'The input is not a valid email address'
  152. }
  153. }
  154. },
  155. // password: {
  156. // validators: {
  157. // notEmpty: {
  158. // message: 'The password is required and can\'t be empty'
  159. // },
  160. // identical: {
  161. // field: 'confirmPassword',
  162. // message: 'The password and its confirm are not the same'
  163. // },
  164. // different: {
  165. // field: 'username',
  166. // message: 'The password can\'t be the same as username'
  167. // }
  168. // }
  169. // },
  170. // confirmPassword: {
  171. // validators: {
  172. // notEmpty: {
  173. // message: 'The confirm password is required and can\'t be empty'
  174. // },
  175. // identical: {
  176. // field: 'password',
  177. // message: 'The password and its confirm are not the same'
  178. // },
  179. // different: {
  180. // field: 'username',
  181. // message: 'The password can\'t be the same as username'
  182. // }
  183. // }
  184. // },
  185. // gender: {
  186. // validators: {
  187. // notEmpty: {
  188. // message: 'The gender is required'
  189. // }
  190. // }
  191. // },
  192. // 'languages[]': {
  193. // validators: {
  194. // notEmpty: {
  195. // message: 'Please specify at least one language you can speak'
  196. // }
  197. // }
  198. // },
  199. captcha: {
  200. validators: {
  201. callback: {
  202. message: 'Wrong answer',
  203. callback: function(value, validator) {
  204. var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
  205. return value == sum;
  206. }
  207. }
  208. }
  209. }
  210. }
  211. });
  212. });
  213. </script>
  214. </body>
  215. </html>