validators.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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="target.php" 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">US Phone number</label>
  68. <div class="col-lg-5">
  69. <input type="text" class="form-control" name="phoneNumberUS" />
  70. </div>
  71. </div>
  72. <div class="form-group">
  73. <label class="col-lg-3 control-label">UK Phone number</label>
  74. <div class="col-lg-5">
  75. <input type="text" class="form-control" name="phoneNumberUK" />
  76. </div>
  77. </div>
  78. <div class="form-group">
  79. <label class="col-lg-3 control-label">Hex color</label>
  80. <div class="col-lg-3">
  81. <input type="text" class="form-control" name="color" />
  82. </div>
  83. </div>
  84. <div class="form-group">
  85. <label class="col-lg-3 control-label">US zip code</label>
  86. <div class="col-lg-3">
  87. <input type="text" class="form-control" name="zipCode" />
  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. feedbackIcons: {
  131. valid: 'glyphicon glyphicon-ok',
  132. invalid: 'glyphicon glyphicon-remove',
  133. validating: 'glyphicon glyphicon-refresh'
  134. },
  135. fields: {
  136. username: {
  137. message: 'The username is not valid',
  138. validators: {
  139. notEmpty: {
  140. message: 'The username is required and can\'t be empty'
  141. },
  142. stringLength: {
  143. min: 6,
  144. max: 30,
  145. message: 'The username must be more than 6 and less than 30 characters long'
  146. },
  147. regexp: {
  148. regexp: /^[a-zA-Z0-9_\.]+$/,
  149. message: 'The username can only consist of alphabetical, number, dot and underscore'
  150. }
  151. }
  152. },
  153. country: {
  154. validators: {
  155. notEmpty: {
  156. message: 'The country is required and can\'t be empty'
  157. }
  158. }
  159. },
  160. acceptTerms: {
  161. validators: {
  162. notEmpty: {
  163. message: 'You have to accept the terms and policies'
  164. }
  165. }
  166. },
  167. email: {
  168. validators: {
  169. notEmpty: {
  170. message: 'The email address is required and can\'t be empty'
  171. },
  172. emailAddress: {
  173. message: 'The input is not a valid email address'
  174. }
  175. }
  176. },
  177. website: {
  178. validators: {
  179. uri: {
  180. allowLocal: true,
  181. message: 'The input is not a valid URL'
  182. }
  183. }
  184. },
  185. phoneNumberUS: {
  186. validators: {
  187. phone: {
  188. message: 'The input is not a valid US phone number'
  189. }
  190. }
  191. },
  192. phoneNumberUK: {
  193. validators: {
  194. phone: {
  195. message: 'The input is not a valid UK phone number',
  196. country: 'GB'
  197. }
  198. }
  199. },
  200. color: {
  201. validators: {
  202. hexColor: {
  203. message: 'The input is not a valid hex color'
  204. }
  205. }
  206. },
  207. zipCode: {
  208. validators: {
  209. zipCode: {
  210. country: 'US',
  211. message: 'The input is not a valid US zip code'
  212. }
  213. }
  214. },
  215. password: {
  216. validators: {
  217. notEmpty: {
  218. message: 'The password is required and can\'t be empty'
  219. },
  220. identical: {
  221. field: 'confirmPassword',
  222. message: 'The password and its confirm are not the same'
  223. }
  224. }
  225. },
  226. confirmPassword: {
  227. validators: {
  228. notEmpty: {
  229. message: 'The confirm password is required and can\'t be empty'
  230. },
  231. identical: {
  232. field: 'password',
  233. message: 'The password and its confirm are not the same'
  234. }
  235. }
  236. },
  237. ages: {
  238. validators: {
  239. lessThan: {
  240. value: 100,
  241. inclusive: true,
  242. message: 'The ages has to be less than 100'
  243. },
  244. greaterThan: {
  245. value: 10,
  246. inclusive: false,
  247. message: 'The ages has to be greater than or equals to 10'
  248. }
  249. }
  250. }
  251. }
  252. });
  253. });
  254. </script>
  255. </body>
  256. </html>