validators.html 11 KB

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