index.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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" action="target.php">
  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-5">
  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-5">
  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">Programming Languages</label>
  97. <div class="col-lg-5">
  98. <div class="checkbox">
  99. <label>
  100. <input type="checkbox" name="programs[]" value="net" /> .Net
  101. </label>
  102. </div>
  103. <div class="checkbox">
  104. <label>
  105. <input type="checkbox" name="programs[]" value="java" /> Java
  106. </label>
  107. </div>
  108. <div class="checkbox">
  109. <label>
  110. <input type="checkbox" name="programs[]" value="c" /> C/C++
  111. </label>
  112. </div>
  113. <div class="checkbox">
  114. <label>
  115. <input type="checkbox" name="programs[]" value="php" /> PHP
  116. </label>
  117. </div>
  118. <div class="checkbox">
  119. <label>
  120. <input type="checkbox" name="programs[]" value="perl" /> Perl
  121. </label>
  122. </div>
  123. <div class="checkbox">
  124. <label>
  125. <input type="checkbox" name="programs[]" value="ruby" /> Ruby
  126. </label>
  127. </div>
  128. <div class="checkbox">
  129. <label>
  130. <input type="checkbox" name="programs[]" value="python" /> Python
  131. </label>
  132. </div>
  133. <div class="checkbox">
  134. <label>
  135. <input type="checkbox" name="programs[]" value="javascript" /> Javascript
  136. </label>
  137. </div>
  138. </div>
  139. </div>
  140. <div class="form-group">
  141. <label class="col-lg-3 control-label" id="captchaOperation"></label>
  142. <div class="col-lg-2">
  143. <input type="text" class="form-control" name="captcha" />
  144. </div>
  145. </div>
  146. <div class="form-group">
  147. <div class="col-lg-9 col-lg-offset-3">
  148. <button type="submit" class="btn btn-primary">Sign up</button>
  149. <button type="button" class="btn btn-info" id="validateBtn">Manual validate</button>
  150. <button type="button" class="btn btn-info" id="resetBtn">Reset form</button>
  151. </div>
  152. </div>
  153. </form>
  154. </div>
  155. </section>
  156. <!-- :form -->
  157. </div>
  158. </div>
  159. <script type="text/javascript">
  160. $(document).ready(function() {
  161. // Generate a simple captcha
  162. function randomNumber(min, max) {
  163. return Math.floor(Math.random() * (max - min + 1) + min);
  164. };
  165. $('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));
  166. $('#defaultForm').bootstrapValidator({
  167. // live: 'disabled',
  168. message: 'This value is not valid',
  169. feedbackIcons: true,
  170. fields: {
  171. username: {
  172. message: 'The username is not valid',
  173. validators: {
  174. notEmpty: {
  175. message: 'The username is required and can\'t be empty'
  176. },
  177. stringLength: {
  178. min: 6,
  179. max: 30,
  180. message: 'The username must be more than 6 and less than 30 characters long'
  181. },
  182. regexp: {
  183. regexp: /^[a-zA-Z0-9_\.]+$/,
  184. message: 'The username can only consist of alphabetical, number, dot and underscore'
  185. },
  186. // remote: {
  187. // url: 'remote.php',
  188. // message: 'The username is not available'
  189. // },
  190. different: {
  191. field: 'password',
  192. message: 'The username and password can\'t be the same as each other'
  193. }
  194. }
  195. },
  196. email: {
  197. validators: {
  198. emailAddress: {
  199. message: 'The input is not a valid email address'
  200. }
  201. }
  202. },
  203. password: {
  204. validators: {
  205. notEmpty: {
  206. message: 'The password is required and can\'t be empty'
  207. },
  208. identical: {
  209. field: 'confirmPassword',
  210. message: 'The password and its confirm are not the same'
  211. },
  212. different: {
  213. field: 'username',
  214. message: 'The password can\'t be the same as username'
  215. }
  216. }
  217. },
  218. confirmPassword: {
  219. validators: {
  220. notEmpty: {
  221. message: 'The confirm password is required and can\'t be empty'
  222. },
  223. identical: {
  224. field: 'password',
  225. message: 'The password and its confirm are not the same'
  226. },
  227. different: {
  228. field: 'username',
  229. message: 'The password can\'t be the same as username'
  230. }
  231. }
  232. },
  233. gender: {
  234. validators: {
  235. notEmpty: {
  236. message: 'The gender is required'
  237. }
  238. }
  239. },
  240. 'languages[]': {
  241. validators: {
  242. notEmpty: {
  243. message: 'Please specify at least one language you can speak'
  244. }
  245. }
  246. },
  247. 'programs[]': {
  248. validators: {
  249. choice: {
  250. min: 2,
  251. max: 4,
  252. message: 'Please choose 2 - 4 programming languages you are good at'
  253. }
  254. }
  255. },
  256. captcha: {
  257. validators: {
  258. callback: {
  259. message: 'Wrong answer',
  260. callback: function(value, validator) {
  261. var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
  262. return value == sum;
  263. }
  264. }
  265. }
  266. }
  267. }
  268. });
  269. // Validate the form manually
  270. $('#validateBtn').click(function() {
  271. $('#defaultForm').bootstrapValidator('validate');
  272. });
  273. $('#resetBtn').click(function() {
  274. $('#defaultForm').data('bootstrapValidator').resetForm(true);
  275. });
  276. });
  277. </script>
  278. </body>
  279. </html>