index.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Total Form Validation</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no">
  7. <link rel="stylesheet" href="fv.css" type="text/css" />
  8. <!--[if IE]>
  9. <style>
  10. .field .tooltip .content{ display:none; opacity:1; }
  11. .field .tooltip:hover .content{ display:block; }
  12. </style>
  13. <![endif]-->
  14. </head>
  15. <body>
  16. <a class='btn github' href='https://github.com/yairEO/validator'>Github</a>
  17. <div id='wrap'>
  18. <div class='options'>
  19. <!-- <label>
  20. <input type='checkbox' id='vfields' />
  21. Vertical orientation
  22. </label> -->
  23. <label>
  24. <input type='checkbox' class='toggleValidationTooltips' />
  25. Disable vlidation tooltips
  26. </label>
  27. </div>
  28. <h1 title='how forms should be done.'>Forms: validation, styling &amp; semantics</h1>
  29. <section class='form'>
  30. <form action="" method="post" novalidate>
  31. <fieldset>
  32. <div class="field">
  33. <label>
  34. <span>Name</span>
  35. <input data-validate-length-range="6" data-validate-words="2" name="name" placeholder="ex. John f. Kennedy" required="required" />
  36. </label>
  37. <div class='tooltip help'>
  38. <span>?</span>
  39. <div class='content'>
  40. <b></b>
  41. <p>Name must be at least 2 words</p>
  42. </div>
  43. </div>
  44. </div>
  45. <div class="field">
  46. <label>
  47. <span>Occupation</span>
  48. <input class='optional' name="occupation" data-validate-length-range="5,15" type="text" />
  49. </label>
  50. <div class='tooltip help'>
  51. <span>?</span>
  52. <div class='content'>
  53. <b></b>
  54. <p>An optional field. This field is only validated when it has a value.<br /><em>Minimum 5 chars, maximum 15</em></p>
  55. </div>
  56. </div>
  57. <span class='extra'>(optional)</span>
  58. </div>
  59. <div class="field">
  60. <label>
  61. <span>HTML5 Regex</span>
  62. <!--<input required="required" type="text" pattern='\d+' />-->
  63. <input type="text" data-validate-length-range="2,6" required="required" placeholder="eg. 123456" pattern="alphanumeric" />
  64. </label>
  65. <div class='tooltip help'>
  66. <span>?</span>
  67. <div class='content'>
  68. <b></b>
  69. <p>This field uses HTML5 "pattern" attribute to be validated.<br /><em>"<strong>\d+</strong>" - only digits are allowed</em></p>
  70. </div>
  71. </div>
  72. </div>
  73. <div class="field">
  74. <label>
  75. <span>email</span>
  76. <input name="email" class='email' required="required" type="email" />
  77. </label>
  78. </div>
  79. <div class="field">
  80. <label>
  81. <span>Confirm email address</span>
  82. <input type="email" class='email' name="confirm_email" data-validate-linked='email' required='required'>
  83. </label>
  84. </div>
  85. <div class="field">
  86. <label>
  87. <span>Number</span>
  88. <input type="number" class='number' name="number" data-validate-minmax="10,100" required='required'>
  89. </label>
  90. <div class='tooltip help'>
  91. <span>?</span>
  92. <div class='content'>
  93. <b></b>
  94. <p>Number must be between 10 and 100</p>
  95. </div>
  96. </div>
  97. </div>
  98. <div class="field">
  99. <label>
  100. <span>Date</span>
  101. <input class='date' type="date" name="date" required='required'>
  102. </label>
  103. </div>
  104. <div class="field">
  105. <label>
  106. <span>Time</span>
  107. <input class='time' type="time" name="time" required='required'>
  108. <div class='tooltip help'>
  109. <span>?</span>
  110. <div class='content'>
  111. <b></b>
  112. <p>Format should be: XX:XX</p>
  113. </div>
  114. </div>
  115. </label>
  116. </div>
  117. <div class="field">
  118. <label>
  119. <span>Password</span>
  120. <input type="password" name="password" data-validate-length="6,8" required='required'>
  121. </label>
  122. <div class='tooltip help'>
  123. <span>?</span>
  124. <div class='content'>
  125. <b></b>
  126. <p>Should be of length 6 OR 8 characters</p>
  127. </div>
  128. </div>
  129. </div>
  130. <div class="field">
  131. <label>
  132. <span>Repeat password</span>
  133. <input type="password" name="password2" data-validate-linked='password' required='required'>
  134. </label>
  135. </div>
  136. <div class="field">
  137. <label>
  138. <span>Telephone</span>
  139. <input type="tel" class='tel' name="phone" required='required' data-validate-length-range="8,20">
  140. </label>
  141. <div class='tooltip help'>
  142. <span>?</span>
  143. <div class='content'>
  144. <b></b>
  145. <p>Notice that for a phone number user can input a '+' sign, a dash '-' or a space ' '</p>
  146. </div>
  147. </div>
  148. </div>
  149. <div class="field">
  150. <label>
  151. <span>Drop down selection</span>
  152. <select required name="dropdown">
  153. <option value="">-- please select --</option>
  154. <option value="o1">Option 1</option>
  155. <option value="o2">Option 2</option>
  156. <option value="o3">Option 3</option>
  157. </select>
  158. </label>
  159. <div class='tooltip help'>
  160. <span>?</span>
  161. <div class='content'>
  162. <b></b>
  163. <p>Choose something or choose not. what shall it be?</p>
  164. </div>
  165. </div>
  166. </div>
  167. <div class="field">
  168. <label>
  169. <span>url</span>
  170. <input name="url" placeholder="http://www.website.com" required="required" type="url" />
  171. </label>
  172. </div>
  173. <div class="field">
  174. <label>
  175. <span>Checkbox</span>
  176. <input required="required" type="checkbox" />
  177. <span>I agree</span>
  178. </label>
  179. </div>
  180. <div class="field">
  181. <label>
  182. <span>Checkbox</span>
  183. <input type="checkbox" />
  184. <span>Optional Checkbox</span>
  185. </label>
  186. </div>
  187. <div class="field multi required">
  188. <label for='multi_first'>
  189. <span>Multifield</span>
  190. </label>
  191. <div class='input'>
  192. <input type="text" name="multi1" maxlength='4' id='multi_first'>
  193. <input type="text" name="multi2" maxlength='4'>
  194. <input type="text" name="multi3" maxlength='4'>
  195. <input type="text" name="multi4" maxlength='4'>
  196. <input type="text" name="multi5" maxlength='4'>
  197. <input type="text" name="multi6" maxlength='4'>
  198. <input data-validate-length-range="24" data-validate-pattern="alphanumeric" id="serial" name="serial" type="hidden" required='required' />
  199. </div>
  200. <div class='tooltip help'>
  201. <span>?</span>
  202. <div class='content'>
  203. <b></b>
  204. <p>This is a multifield, which let the user input a serial number or credit card number for example, and the trick is to validate the combined result, which is stored in a hidden field</p>
  205. </div>
  206. </div>
  207. </div>
  208. <div class="field">
  209. <label>
  210. <span>File upload</span>
  211. <input type='file' required>
  212. </label>
  213. </div>
  214. <div class="field">
  215. <label>
  216. <span>message</span>
  217. <textarea required="required" name='message'></textarea>
  218. </label>
  219. </div>
  220. </fieldset>
  221. <fieldset>
  222. <p>
  223. There is a hidden "required" form field below, notice it will not be validated due to its lack of visibility.<br>
  224. The reason for this is that sometimes there is a section in a form that is not visible until some user "action" is taken,
  225. and changing form fields to be "required" on-the-fly is undesirable.
  226. </p>
  227. <input name="somethingHidden" required="required" type="text" style='display:none' />
  228. </fieldset>
  229. <button type='submit'>Submit</button>
  230. <button type='reset'>Reset</button>
  231. </form>
  232. </section>
  233. </div>
  234. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  235. <script src="multifield.js"></script>
  236. <script src="validator.js"></script>
  237. <script>
  238. // initialize a validator instance from the "FormValidator" constructor.
  239. // A "<form>" element is optionally passed as an argument, but is not a must
  240. var validator = new FormValidator({"events" : ['blur', 'input', 'change']}, document.forms[0]);
  241. // on form "submit" event
  242. document.forms[0].onsubmit = function(e){
  243. var submit = true,
  244. validatorResult = validator.checkAll(this);
  245. console.log(validatorResult);
  246. return !!validatorResult.valid;
  247. };
  248. // on form "reset" event
  249. document.forms[0].onreset = function(e){
  250. validator.reset();
  251. };
  252. // stuff related ONLY for this demo page:
  253. $('.toggleValidationTooltips').change(function(){
  254. validator.settings.alerts = !this.checked;
  255. if( this.checked )
  256. $('form .alert').remove();
  257. }).prop('checked',false);
  258. </script>
  259. </body>
  260. </html>