validators.html 12 KB

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