validators.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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="page-header">
  17. <h1>Bootstrap Validate plugin</h1>
  18. </div>
  19. <div class="col-lg-8 col-lg-offset-2">
  20. <form id="defaultForm" method="post" action="validators.html" class="form-horizontal">
  21. <fieldset>
  22. <legend>Not Empty validator</legend>
  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">Country</label>
  31. <div class="col-lg-5">
  32. <select class="form-control" name="country">
  33. <option value="">-- Select a country --</option>
  34. <option value="fr">France</option>
  35. <option value="de">Germany</option>
  36. <option value="it">Italy</option>
  37. <option value="jp">Japan</option>
  38. <option value="ru">Russia</option>
  39. <option value="gb">United Kingdom</option>
  40. <option value="us">United State</option>
  41. </select>
  42. </div>
  43. </div>
  44. <div class="form-group">
  45. <div class="col-lg-9 col-lg-offset-3">
  46. <div class="checkbox">
  47. <input type="checkbox" name="acceptTerms" /> Accept the terms and policies
  48. </div>
  49. </div>
  50. </div>
  51. </fieldset>
  52. <fieldset>
  53. <legend>Regular expression based validators</legend>
  54. <div class="form-group">
  55. <label class="col-lg-3 control-label">Email address</label>
  56. <div class="col-lg-5">
  57. <input type="text" class="form-control" name="email" />
  58. </div>
  59. </div>
  60. <div class="form-group">
  61. <label class="col-lg-3 control-label">Website</label>
  62. <div class="col-lg-5">
  63. <input type="text" class="form-control" name="website" placeholder="http://" />
  64. </div>
  65. </div>
  66. <div class="form-group">
  67. <label class="col-lg-3 control-label">Phone number</label>
  68. <div class="col-lg-5">
  69. <input type="text" class="form-control" name="phoneNumber" />
  70. </div>
  71. </div>
  72. <div class="form-group">
  73. <label class="col-lg-3 control-label">Hex color</label>
  74. <div class="col-lg-3">
  75. <input type="text" class="form-control" name="color" />
  76. </div>
  77. </div>
  78. <div class="form-group">
  79. <label class="col-lg-3 control-label">US zip code</label>
  80. <div class="col-lg-3">
  81. <input type="text" class="form-control" name="zipCode" />
  82. </div>
  83. </div>
  84. </fieldset>
  85. <fieldset>
  86. <legend>Identical validator</legend>
  87. <div class="form-group">
  88. <label class="col-lg-3 control-label">Password</label>
  89. <div class="col-lg-5">
  90. <input type="password" class="form-control" name="password" />
  91. </div>
  92. </div>
  93. <div class="form-group">
  94. <label class="col-lg-3 control-label">Retype password</label>
  95. <div class="col-lg-5">
  96. <input type="password" class="form-control" name="confirmPassword" />
  97. </div>
  98. </div>
  99. </fieldset>
  100. <fieldset>
  101. <legend>Other validators</legend>
  102. <div class="form-group">
  103. <label class="col-lg-3 control-label">Ages</label>
  104. <div class="col-lg-3">
  105. <input type="text" class="form-control" name="ages" />
  106. </div>
  107. </div>
  108. </fieldset>
  109. <div class="form-group">
  110. <div class="col-lg-9 col-lg-offset-3">
  111. <button type="submit" class="btn btn-primary">Submit</button>
  112. </div>
  113. </div>
  114. </form>
  115. </div>
  116. </section>
  117. <!-- :form -->
  118. </div>
  119. </div>
  120. <script type="text/javascript">
  121. $(document).ready(function() {
  122. $('#defaultForm').bootstrapValidator({
  123. message: 'This value is not valid',
  124. fields: {
  125. username: {
  126. message: 'The username is not valid',
  127. validators: {
  128. notEmpty: {
  129. message: 'The username is required and can\'t be empty'
  130. },
  131. stringLength: {
  132. min: 6,
  133. max: 30,
  134. message: 'The username must be more than 6 and less than 30 characters long'
  135. },
  136. regexp: {
  137. regexp: /^[a-zA-Z0-9_\.]+$/,
  138. message: 'The username can only consist of alphabetical, number, dot and underscore'
  139. }
  140. }
  141. },
  142. country: {
  143. validators: {
  144. notEmpty: {
  145. message: 'The country is required and can\'t be empty'
  146. }
  147. }
  148. },
  149. acceptTerms: {
  150. validators: {
  151. notEmpty: {
  152. message: 'You have to accept the terms and policies'
  153. }
  154. }
  155. },
  156. email: {
  157. validators: {
  158. notEmpty: {
  159. message: 'The email address is required and can\'t be empty'
  160. },
  161. emailAddress: {
  162. message: 'The input is not a valid email address'
  163. }
  164. }
  165. },
  166. website: {
  167. validators: {
  168. uri: {
  169. message: 'The input is not a valid URL'
  170. }
  171. }
  172. },
  173. phoneNumber: {
  174. validators: {
  175. digits: {
  176. message: 'The value can contain only digits'
  177. }
  178. }
  179. },
  180. color: {
  181. validators: {
  182. hexColor: {
  183. message: 'The input is not a valid hex color'
  184. }
  185. }
  186. },
  187. zipCode: {
  188. validators: {
  189. usZipCode: {
  190. message: 'The input is not a valid US zip code'
  191. }
  192. }
  193. },
  194. password: {
  195. validators: {
  196. notEmpty: {
  197. message: 'The password is required and can\'t be empty'
  198. },
  199. identical: {
  200. field: 'confirmPassword',
  201. message: 'The password and its confirm are not the same'
  202. }
  203. }
  204. },
  205. confirmPassword: {
  206. validators: {
  207. notEmpty: {
  208. message: 'The confirm password is required and can\'t be empty'
  209. },
  210. identical: {
  211. field: 'password',
  212. message: 'The password and its confirm are not the same'
  213. }
  214. }
  215. },
  216. ages: {
  217. validators: {
  218. lessThan: {
  219. value: 100,
  220. inclusive: true,
  221. message: 'The ages has to be less than 100'
  222. },
  223. greaterThan: {
  224. value: 10,
  225. inclusive: false,
  226. message: 'The ages has to be greater than or equals to 10'
  227. }
  228. }
  229. }
  230. }
  231. });
  232. });
  233. </script>
  234. </body>
  235. </html>