validators.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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-5">
  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. <div class="form-group">
  67. <label class="col-lg-3 control-label">US zip code</label>
  68. <div class="col-lg-3">
  69. <input type="text" class="form-control" name="zipCode" />
  70. </div>
  71. </div>
  72. </fieldset>
  73. <fieldset>
  74. <legend>Identical validator</legend>
  75. <div class="form-group">
  76. <label class="col-lg-3 control-label">Password</label>
  77. <div class="col-lg-5">
  78. <input type="password" class="form-control" name="password" />
  79. </div>
  80. </div>
  81. <div class="form-group">
  82. <label class="col-lg-3 control-label">Retype password</label>
  83. <div class="col-lg-5">
  84. <input type="password" class="form-control" name="confirmPassword" />
  85. </div>
  86. </div>
  87. </fieldset>
  88. <fieldset>
  89. <legend>Other validators</legend>
  90. <div class="form-group">
  91. <label class="col-lg-3 control-label">Ages</label>
  92. <div class="col-lg-3">
  93. <input type="text" class="form-control" name="ages" />
  94. </div>
  95. </div>
  96. </fieldset>
  97. <div class="form-group">
  98. <div class="col-lg-9 col-lg-offset-3">
  99. <button type="submit" class="btn btn-primary">Submit</button>
  100. </div>
  101. </div>
  102. </form>
  103. </div>
  104. </section>
  105. <!-- :form -->
  106. </div>
  107. </div>
  108. <script type="text/javascript">
  109. $(document).ready(function() {
  110. $('#defaultForm').bootstrapValidate({
  111. fields: {
  112. username: {
  113. message: 'The username is not valid',
  114. validator: {
  115. notEmpty: {
  116. message: 'The username is required and can\'t be empty'
  117. },
  118. stringLength: {
  119. min: 6,
  120. max: 30,
  121. message: 'The username must be more than 6 and less than 30 characters long'
  122. },
  123. regexp: {
  124. regexp: /^[a-zA-Z0-9_\.]+$/,
  125. message: 'The username can only consist of alphabetical, number, dot and underscore'
  126. }
  127. }
  128. },
  129. acceptTerms: {
  130. validator: {
  131. notEmpty: {
  132. message: 'You have to accept the terms and policies'
  133. }
  134. }
  135. },
  136. email: {
  137. validator: {
  138. notEmpty: {
  139. message: 'The email address is required and can\'t be empty'
  140. },
  141. emailAddress: {
  142. message: 'The input is not a valid email address'
  143. }
  144. }
  145. },
  146. website: {
  147. validator: {
  148. uri: {
  149. message: 'The input is not a valid URL'
  150. }
  151. }
  152. },
  153. phoneNumber: {
  154. validator: {
  155. digits: {
  156. message: 'The value can contain only digits'
  157. }
  158. }
  159. },
  160. color: {
  161. validator: {
  162. hexColor: {
  163. message: 'The input is not a valid hex color'
  164. }
  165. }
  166. },
  167. zipCode: {
  168. validator: {
  169. usZipCode: {
  170. message: 'The input is not a valid US zip code'
  171. }
  172. }
  173. },
  174. password: {
  175. validator: {
  176. notEmpty: {
  177. message: 'The password is required and can\'t be empty'
  178. },
  179. identical: {
  180. field: 'confirmPassword',
  181. message: 'The password and its confirm are not the same'
  182. }
  183. }
  184. },
  185. confirmPassword: {
  186. validator: {
  187. notEmpty: {
  188. message: 'The confirm password is required and can\'t be empty'
  189. },
  190. identical: {
  191. field: 'password',
  192. message: 'The password and its confirm are not the same'
  193. }
  194. }
  195. },
  196. ages: {
  197. validator: {
  198. lessThan: {
  199. value: 100,
  200. inclusive: true,
  201. message: 'The ages has to be less than 100'
  202. },
  203. greaterThan: {
  204. value: 10,
  205. inclusive: false,
  206. message: 'The ages has to be greater than or equals to 10'
  207. }
  208. }
  209. }
  210. },
  211. message: 'This value is not valid',
  212. iconClass: {
  213. valid: 'icon-ok',
  214. invalid: 'icon-remove'
  215. }
  216. });
  217. });
  218. </script>
  219. </body>
  220. </html>