index.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. <!-- Include the FontAwesome CSS if you want to use feedback icons provided by FontAwesome -->
  8. <!--<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" />-->
  9. <script type="text/javascript" src="../vendor/jquery/jquery-1.10.2.min.js"></script>
  10. <script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
  11. <script type="text/javascript" src="../dist/js/bootstrapValidator.js"></script>
  12. </head>
  13. <body>
  14. <div class="container">
  15. <div class="row">
  16. <!-- form: -->
  17. <section>
  18. <div class="col-lg-8 col-lg-offset-2">
  19. <div class="page-header">
  20. <h2>Sign up</h2>
  21. </div>
  22. <form id="defaultForm" method="post" class="form-horizontal" action="target.php">
  23. <div class="form-group">
  24. <label class="col-lg-3 control-label">Username</label>
  25. <div class="col-lg-5">
  26. <input type="text" class="form-control" name="username" />
  27. </div>
  28. </div>
  29. <div class="form-group">
  30. <label class="col-lg-3 control-label">Email address</label>
  31. <div class="col-lg-5">
  32. <input type="text" class="form-control" name="email" />
  33. </div>
  34. </div>
  35. <div class="form-group">
  36. <label class="col-lg-3 control-label">Password</label>
  37. <div class="col-lg-5">
  38. <input type="password" class="form-control" name="password" />
  39. </div>
  40. </div>
  41. <div class="form-group">
  42. <label class="col-lg-3 control-label">Retype password</label>
  43. <div class="col-lg-5">
  44. <input type="password" class="form-control" name="confirmPassword" />
  45. </div>
  46. </div>
  47. <div class="form-group">
  48. <label class="col-lg-3 control-label">Gender</label>
  49. <div class="col-lg-5">
  50. <div class="radio">
  51. <label>
  52. <input type="radio" name="gender" value="male" /> Male
  53. </label>
  54. </div>
  55. <div class="radio">
  56. <label>
  57. <input type="radio" name="gender" value="female" /> Female
  58. </label>
  59. </div>
  60. <div class="radio">
  61. <label>
  62. <input type="radio" name="gender" value="other" /> Other
  63. </label>
  64. </div>
  65. </div>
  66. </div>
  67. <div class="form-group">
  68. <label class="col-lg-3 control-label">Birthday</label>
  69. <div class="col-lg-5">
  70. <input type="text" class="form-control" name="birthday" /> (YYYY/MM/DD)
  71. </div>
  72. </div>
  73. <div class="form-group">
  74. <label class="col-lg-3 control-label">Languages</label>
  75. <div class="col-lg-5">
  76. <div class="checkbox">
  77. <label>
  78. <input type="checkbox" name="languages[]" value="english" /> English
  79. </label>
  80. </div>
  81. <div class="checkbox">
  82. <label>
  83. <input type="checkbox" name="languages[]" value="french" /> French
  84. </label>
  85. </div>
  86. <div class="checkbox">
  87. <label>
  88. <input type="checkbox" name="languages[]" value="german" /> German
  89. </label>
  90. </div>
  91. <div class="checkbox">
  92. <label>
  93. <input type="checkbox" name="languages[]" value="russian" /> Russian
  94. </label>
  95. </div>
  96. <div class="checkbox">
  97. <label>
  98. <input type="checkbox" name="languages[]" value="other" /> Other
  99. </label>
  100. </div>
  101. </div>
  102. </div>
  103. <div class="form-group">
  104. <label class="col-lg-3 control-label">Programming Languages</label>
  105. <div class="col-lg-5">
  106. <div class="checkbox">
  107. <label>
  108. <input type="checkbox" name="programs[]" value="net" /> .Net
  109. </label>
  110. </div>
  111. <div class="checkbox">
  112. <label>
  113. <input type="checkbox" name="programs[]" value="java" /> Java
  114. </label>
  115. </div>
  116. <div class="checkbox">
  117. <label>
  118. <input type="checkbox" name="programs[]" value="c" /> C/C++
  119. </label>
  120. </div>
  121. <div class="checkbox">
  122. <label>
  123. <input type="checkbox" name="programs[]" value="php" /> PHP
  124. </label>
  125. </div>
  126. <div class="checkbox">
  127. <label>
  128. <input type="checkbox" name="programs[]" value="perl" /> Perl
  129. </label>
  130. </div>
  131. <div class="checkbox">
  132. <label>
  133. <input type="checkbox" name="programs[]" value="ruby" /> Ruby
  134. </label>
  135. </div>
  136. <div class="checkbox">
  137. <label>
  138. <input type="checkbox" name="programs[]" value="python" /> Python
  139. </label>
  140. </div>
  141. <div class="checkbox">
  142. <label>
  143. <input type="checkbox" name="programs[]" value="javascript" /> Javascript
  144. </label>
  145. </div>
  146. </div>
  147. </div>
  148. <div class="form-group">
  149. <label class="col-lg-3 control-label" id="captchaOperation"></label>
  150. <div class="col-lg-2">
  151. <input type="text" class="form-control" name="captcha" />
  152. </div>
  153. </div>
  154. <div class="form-group">
  155. <div class="col-lg-9 col-lg-offset-3">
  156. <button type="submit" class="btn btn-primary">Sign up</button>
  157. <button type="button" class="btn btn-info" id="validateBtn">Manual validate</button>
  158. <button type="button" class="btn btn-info" id="resetBtn">Reset form</button>
  159. </div>
  160. </div>
  161. </form>
  162. </div>
  163. </section>
  164. <!-- :form -->
  165. </div>
  166. </div>
  167. <script type="text/javascript">
  168. $(document).ready(function() {
  169. // Generate a simple captcha
  170. function randomNumber(min, max) {
  171. return Math.floor(Math.random() * (max - min + 1) + min);
  172. };
  173. $('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));
  174. $('#defaultForm').bootstrapValidator({
  175. // live: 'disabled',
  176. message: 'This value is not valid',
  177. feedbackIcons: {
  178. valid: 'glyphicon glyphicon-ok',
  179. invalid: 'glyphicon glyphicon-remove',
  180. validating: 'glyphicon glyphicon-refresh'
  181. },
  182. fields: {
  183. username: {
  184. message: 'The username is not valid',
  185. validators: {
  186. notEmpty: {
  187. message: 'The username is required and can\'t be empty'
  188. },
  189. stringLength: {
  190. min: 6,
  191. max: 30,
  192. message: 'The username must be more than 6 and less than 30 characters long'
  193. },
  194. regexp: {
  195. regexp: /^[a-zA-Z0-9_\.]+$/,
  196. message: 'The username can only consist of alphabetical, number, dot and underscore'
  197. },
  198. // remote: {
  199. // url: 'remote.php',
  200. // message: 'The username is not available'
  201. // },
  202. different: {
  203. field: 'password',
  204. message: 'The username and password can\'t be the same as each other'
  205. }
  206. }
  207. },
  208. email: {
  209. validators: {
  210. emailAddress: {
  211. message: 'The input is not a valid email address'
  212. }
  213. }
  214. },
  215. password: {
  216. validators: {
  217. notEmpty: {
  218. message: 'The password is required and can\'t be empty'
  219. },
  220. identical: {
  221. field: 'confirmPassword',
  222. message: 'The password and its confirm are not the same'
  223. },
  224. different: {
  225. field: 'username',
  226. message: 'The password can\'t be the same as username'
  227. }
  228. }
  229. },
  230. confirmPassword: {
  231. validators: {
  232. notEmpty: {
  233. message: 'The confirm password is required and can\'t be empty'
  234. },
  235. identical: {
  236. field: 'password',
  237. message: 'The password and its confirm are not the same'
  238. },
  239. different: {
  240. field: 'username',
  241. message: 'The password can\'t be the same as username'
  242. }
  243. }
  244. },
  245. birthday: {
  246. validators: {
  247. date: {
  248. format: 'YYYY/MM/DD',
  249. message: 'The birthday is not valid'
  250. }
  251. }
  252. },
  253. gender: {
  254. validators: {
  255. notEmpty: {
  256. message: 'The gender is required'
  257. }
  258. }
  259. },
  260. 'languages[]': {
  261. validators: {
  262. notEmpty: {
  263. message: 'Please specify at least one language you can speak'
  264. }
  265. }
  266. },
  267. 'programs[]': {
  268. validators: {
  269. choice: {
  270. min: 2,
  271. max: 4,
  272. message: 'Please choose 2 - 4 programming languages you are good at'
  273. }
  274. }
  275. },
  276. captcha: {
  277. validators: {
  278. callback: {
  279. message: 'Wrong answer',
  280. callback: function(value, validator) {
  281. var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
  282. return value == sum;
  283. }
  284. }
  285. }
  286. }
  287. }
  288. });
  289. // Validate the form manually
  290. $('#validateBtn').click(function() {
  291. $('#defaultForm').bootstrapValidator('validate');
  292. });
  293. $('#resetBtn').click(function() {
  294. $('#defaultForm').data('bootstrapValidator').resetForm(true);
  295. });
  296. });
  297. </script>
  298. </body>
  299. </html>