validators.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Bootstrap Validate demo</title>
  5. <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
  6. <!--[if IE 7]>
  7. <link rel="stylesheet" href="../vendor/font-awesome/css/font-awesome-ie7.min.css">
  8. <![endif]-->
  9. <link rel="stylesheet" href="../vendor/font-awesome/css/font-awesome.min.css"/>
  10. <script type="text/javascript" src="../vendor/jquery/jquery-1.10.2.min.js"></script>
  11. <script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
  12. <script type="text/javascript" src="../dist/js/bootstrapvalidate.js"></script>
  13. </head>
  14. <body>
  15. <div class="container">
  16. <div class="row">
  17. <!-- form: -->
  18. <section>
  19. <div class="page-header">
  20. <h1>Bootstrap Validate plugin</h1>
  21. </div>
  22. <div class="col-lg-8 col-lg-offset-2">
  23. <form id="defaultForm" method="post" class="form-horizontal">
  24. <fieldset>
  25. <legend>Not Empty validator</legend>
  26. <div class="form-group">
  27. <label class="col-lg-3 control-label">Username</label>
  28. <div class="col-lg-9">
  29. <input type="text" class="form-control" name="username" />
  30. </div>
  31. </div>
  32. <div class="form-group">
  33. <div class="col-lg-9 col-lg-offset-3">
  34. <div class="checkbox">
  35. <input type="checkbox" name="acceptTerms" /> Accept the terms and policies
  36. </div>
  37. </div>
  38. </div>
  39. </fieldset>
  40. <fieldset>
  41. <legend>Regular expression based validators</legend>
  42. <div class="form-group">
  43. <label class="col-lg-3 control-label">Email address</label>
  44. <div class="col-lg-5">
  45. <input type="text" class="form-control" name="email" />
  46. </div>
  47. </div>
  48. <div class="form-group">
  49. <label class="col-lg-3 control-label">Website</label>
  50. <div class="col-lg-5">
  51. <input type="text" class="form-control" name="website" placeholder="http://" />
  52. </div>
  53. </div>
  54. <div class="form-group">
  55. <label class="col-lg-3 control-label">Phone number</label>
  56. <div class="col-lg-5">
  57. <input type="text" class="form-control" name="phoneNumber" />
  58. </div>
  59. </div>
  60. <div class="form-group">
  61. <label class="col-lg-3 control-label">Hex color</label>
  62. <div class="col-lg-3">
  63. <input type="text" class="form-control" name="color" />
  64. </div>
  65. </div>
  66. </fieldset>
  67. <fieldset>
  68. <legend>Identical validator</legend>
  69. <div class="form-group">
  70. <label class="col-lg-3 control-label">Password</label>
  71. <div class="col-lg-5">
  72. <input type="password" class="form-control" name="password" />
  73. </div>
  74. </div>
  75. <div class="form-group">
  76. <label class="col-lg-3 control-label">Retype password</label>
  77. <div class="col-lg-5">
  78. <input type="password" class="form-control" name="confirmPassword" />
  79. </div>
  80. </div>
  81. </fieldset>
  82. <fieldset>
  83. <legend>Other validators</legend>
  84. <div class="form-group">
  85. <label class="col-lg-3 control-label">Ages</label>
  86. <div class="col-lg-3">
  87. <input type="text" class="form-control" name="ages" />
  88. </div>
  89. </div>
  90. </fieldset>
  91. <div class="form-group">
  92. <div class="col-lg-9 col-lg-offset-3">
  93. <button type="submit" class="btn btn-primary">Sign up</button>
  94. </div>
  95. </div>
  96. </form>
  97. </div>
  98. </section>
  99. <!-- :form -->
  100. </div>
  101. </div>
  102. <script type="text/javascript">
  103. $(document).ready(function() {
  104. $('#defaultForm').bootstrapValidate({
  105. fields: {
  106. username: {
  107. message: 'The username is not valid',
  108. validator: {
  109. notEmpty: {
  110. message: 'The username is required and can\'t be empty'
  111. },
  112. stringLength: {
  113. min: 6,
  114. max: 30,
  115. message: 'The username must be more than 6 and less than 30 characters long'
  116. },
  117. regexp: {
  118. regexp: /^[a-zA-Z0-9_\.]+$/,
  119. message: 'The username can only consist of alphabetical, number, dot and underscore'
  120. }
  121. }
  122. },
  123. acceptTerms: {
  124. validator: {
  125. notEmpty: {
  126. message: 'You have to accept the terms and policies'
  127. }
  128. }
  129. },
  130. email: {
  131. validator: {
  132. notEmpty: {
  133. message: 'The email address is required and can\'t be empty'
  134. },
  135. emailAddress: {
  136. message: 'The input is not a valid email address'
  137. }
  138. }
  139. },
  140. website: {
  141. validator: {
  142. uri: {
  143. message: 'The input is not a valid URL'
  144. }
  145. }
  146. },
  147. phoneNumber: {
  148. validator: {
  149. digits: {
  150. message: 'The value can contain only digits'
  151. }
  152. }
  153. },
  154. color: {
  155. validator: {
  156. hexColor: {
  157. message: 'The input is not a valid hex color'
  158. }
  159. }
  160. },
  161. password: {
  162. validator: {
  163. notEmpty: {
  164. message: 'The password is required and can\'t be empty'
  165. },
  166. identical: {
  167. field: 'confirmPassword',
  168. message: 'The password and its confirm are not the same'
  169. }
  170. }
  171. },
  172. confirmPassword: {
  173. validator: {
  174. notEmpty: {
  175. message: 'The confirm password is required and can\'t be empty'
  176. },
  177. identical: {
  178. field: 'password',
  179. message: 'The password and its confirm are not the same'
  180. }
  181. }
  182. },
  183. ages: {
  184. validator: {
  185. lessThan: {
  186. value: 100,
  187. inclusive: true,
  188. message: 'The ages has to be less than 100'
  189. },
  190. greaterThan: {
  191. value: 10,
  192. inclusive: false,
  193. message: 'The ages has to be greater than or equals to 10'
  194. }
  195. }
  196. }
  197. },
  198. message: 'This value is not valid',
  199. iconClass: {
  200. valid: 'icon-ok',
  201. invalid: 'icon-remove'
  202. }
  203. });
  204. });
  205. </script>
  206. </body>
  207. </html>