index.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. </div>
  151. </div>
  152. </form>
  153. </div>
  154. </section>
  155. <!-- :form -->
  156. </div>
  157. </div>
  158. <script type="text/javascript">
  159. $(document).ready(function() {
  160. // Generate a simple captcha
  161. function randomNumber(min, max) {
  162. return Math.floor(Math.random() * (max - min + 1) + min);
  163. };
  164. $('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));
  165. $('#defaultForm').bootstrapValidator({
  166. live: 'enabled',
  167. message: 'This value is not valid',
  168. feedbackIcons: true,
  169. fields: {
  170. username: {
  171. message: 'The username is not valid',
  172. validators: {
  173. notEmpty: {
  174. message: 'The username is required and can\'t be empty'
  175. },
  176. stringLength: {
  177. min: 6,
  178. max: 30,
  179. message: 'The username must be more than 6 and less than 30 characters long'
  180. },
  181. regexp: {
  182. regexp: /^[a-zA-Z0-9_\.]+$/,
  183. message: 'The username can only consist of alphabetical, number, dot and underscore'
  184. },
  185. // remote: {
  186. // url: 'remote.php',
  187. // message: 'The username is not available'
  188. // },
  189. different: {
  190. field: 'password',
  191. message: 'The username and password can\'t be the same as each other'
  192. }
  193. }
  194. },
  195. email: {
  196. validators: {
  197. emailAddress: {
  198. message: 'The input is not a valid email address'
  199. }
  200. }
  201. },
  202. password: {
  203. validators: {
  204. notEmpty: {
  205. message: 'The password is required and can\'t be empty'
  206. },
  207. identical: {
  208. field: 'confirmPassword',
  209. message: 'The password and its confirm are not the same'
  210. },
  211. different: {
  212. field: 'username',
  213. message: 'The password can\'t be the same as username'
  214. }
  215. }
  216. },
  217. confirmPassword: {
  218. validators: {
  219. notEmpty: {
  220. message: 'The confirm password is required and can\'t be empty'
  221. },
  222. identical: {
  223. field: 'password',
  224. message: 'The password and its confirm are not the same'
  225. },
  226. different: {
  227. field: 'username',
  228. message: 'The password can\'t be the same as username'
  229. }
  230. }
  231. },
  232. gender: {
  233. validators: {
  234. notEmpty: {
  235. message: 'The gender is required'
  236. }
  237. }
  238. },
  239. 'languages[]': {
  240. validators: {
  241. notEmpty: {
  242. message: 'Please specify at least one language you can speak'
  243. }
  244. }
  245. },
  246. 'programs[]': {
  247. validators: {
  248. choice: {
  249. min: 2,
  250. max: 4,
  251. message: 'Please choose 2 - 4 programming languages you are good at'
  252. }
  253. }
  254. },
  255. captcha: {
  256. validators: {
  257. callback: {
  258. message: 'Wrong answer',
  259. callback: function(value, validator) {
  260. var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
  261. return value == sum;
  262. }
  263. }
  264. }
  265. }
  266. }
  267. });
  268. // Validate the form manually
  269. $('#validateBtn').click(function() {
  270. $('#defaultForm').bootstrapValidator('validate');
  271. });
  272. });
  273. </script>
  274. </body>
  275. </html>