index.html 13 KB

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