validators.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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-5 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. </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. feedbackIcons: {
  125. valid: 'glyphicon glyphicon-ok',
  126. invalid: 'glyphicon glyphicon-remove',
  127. validating: 'glyphicon glyphicon-refresh'
  128. },
  129. fields: {
  130. username: {
  131. message: 'The username is not valid',
  132. validators: {
  133. notEmpty: {
  134. message: 'The username is required and can\'t be empty'
  135. },
  136. stringLength: {
  137. min: 6,
  138. max: 30,
  139. message: 'The username must be more than 6 and less than 30 characters long'
  140. },
  141. regexp: {
  142. regexp: /^[a-zA-Z0-9_\.]+$/,
  143. message: 'The username can only consist of alphabetical, number, dot and underscore'
  144. }
  145. }
  146. },
  147. country: {
  148. validators: {
  149. notEmpty: {
  150. message: 'The country is required and can\'t be empty'
  151. }
  152. }
  153. },
  154. acceptTerms: {
  155. validators: {
  156. notEmpty: {
  157. message: 'You have to accept the terms and policies'
  158. }
  159. }
  160. },
  161. email: {
  162. validators: {
  163. notEmpty: {
  164. message: 'The email address is required and can\'t be empty'
  165. },
  166. emailAddress: {
  167. message: 'The input is not a valid email address'
  168. }
  169. }
  170. },
  171. website: {
  172. validators: {
  173. uri: {
  174. message: 'The input is not a valid URL'
  175. }
  176. }
  177. },
  178. phoneNumber: {
  179. validators: {
  180. digits: {
  181. message: 'The value can contain only digits'
  182. }
  183. }
  184. },
  185. color: {
  186. validators: {
  187. hexColor: {
  188. message: 'The input is not a valid hex color'
  189. }
  190. }
  191. },
  192. zipCode: {
  193. validators: {
  194. zipCode: {
  195. country: 'US',
  196. message: 'The input is not a valid US zip code'
  197. }
  198. }
  199. },
  200. password: {
  201. validators: {
  202. notEmpty: {
  203. message: 'The password is required and can\'t be empty'
  204. },
  205. identical: {
  206. field: 'confirmPassword',
  207. message: 'The password and its confirm are not the same'
  208. }
  209. }
  210. },
  211. confirmPassword: {
  212. validators: {
  213. notEmpty: {
  214. message: 'The confirm password is required and can\'t be empty'
  215. },
  216. identical: {
  217. field: 'password',
  218. message: 'The password and its confirm are not the same'
  219. }
  220. }
  221. },
  222. ages: {
  223. validators: {
  224. lessThan: {
  225. value: 100,
  226. inclusive: true,
  227. message: 'The ages has to be less than 100'
  228. },
  229. greaterThan: {
  230. value: 10,
  231. inclusive: false,
  232. message: 'The ages has to be greater than or equals to 10'
  233. }
  234. }
  235. }
  236. }
  237. });
  238. });
  239. </script>
  240. </body>
  241. </html>