index.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. <!--
  46. <div class="form-group">
  47. <label class="col-lg-3 control-label" id="captchaOperation"></label>
  48. <div class="col-lg-2">
  49. <input type="text" class="form-control" name="captcha" />
  50. </div>
  51. </div>
  52. -->
  53. <div class="form-group">
  54. <div class="col-lg-9 col-lg-offset-3">
  55. <button type="submit" class="btn btn-primary">Sign up</button>
  56. </div>
  57. </div>
  58. </form>
  59. </div>
  60. </section>
  61. <!-- :form -->
  62. </div>
  63. </div>
  64. <script type="text/javascript">
  65. $(document).ready(function() {
  66. // Generate a simple captcha
  67. function randomNumber(min, max) {
  68. return Math.floor(Math.random() * (max - min + 1) + min);
  69. };
  70. $('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));
  71. $('#defaultForm').bootstrapValidator({
  72. message: 'This value is not valid',
  73. fields: {
  74. username: {
  75. message: 'The username is not valid',
  76. validators: {
  77. notEmpty: {
  78. message: 'The username is required and can\'t be empty'
  79. },
  80. stringLength: {
  81. min: 6,
  82. max: 30,
  83. message: 'The username must be more than 6 and less than 30 characters long'
  84. },
  85. regexp: {
  86. regexp: /^[a-zA-Z0-9_\.]+$/,
  87. message: 'The username can only consist of alphabetical, number, dot and underscore'
  88. },
  89. different: {
  90. field: 'password',
  91. message: 'The username and password can\'t be the same as each other'
  92. }
  93. }
  94. },
  95. email: {
  96. validators: {
  97. notEmpty: {
  98. message: 'The email address is required and can\'t be empty'
  99. },
  100. emailAddress: {
  101. message: 'The input is not a valid email address'
  102. }
  103. }
  104. },
  105. password: {
  106. validators: {
  107. notEmpty: {
  108. message: 'The password is required and can\'t be empty'
  109. },
  110. identical: {
  111. field: 'confirmPassword',
  112. message: 'The password and its confirm are not the same'
  113. },
  114. different: {
  115. field: 'username',
  116. message: 'The password can\'t be the same as username'
  117. }
  118. }
  119. },
  120. confirmPassword: {
  121. validators: {
  122. notEmpty: {
  123. message: 'The confirm password is required and can\'t be empty'
  124. },
  125. identical: {
  126. field: 'password',
  127. message: 'The password and its confirm are not the same'
  128. },
  129. different: {
  130. field: 'username',
  131. message: 'The password can\'t be the same as username'
  132. }
  133. }
  134. },
  135. captcha: {
  136. validators: {
  137. callback: {
  138. message: 'Wrong answer',
  139. callback: function(value, validator) {
  140. var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
  141. return value == sum;
  142. }
  143. }
  144. }
  145. }
  146. }
  147. });
  148. });
  149. </script>
  150. </body>
  151. </html>