validate.html 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <th:block th:include="include :: header('表单校验')" />
  5. </head>
  6. <body class="gray-bg">
  7. <div class="wrapper wrapper-content animated fadeInRight">
  8. <div class="row">
  9. <div class="col-sm-12">
  10. <div class="ibox float-e-margins">
  11. <div class="ibox-title">
  12. <h5>jQuery Validate 简介</h5>
  13. </div>
  14. <div class="ibox-content">
  15. <p>jquery.validate.js 是一款优秀的jQuery表单验证插件。它具有如下特点:</p>
  16. <ul>
  17. <li>安装简单</li>
  18. <li>内置超过20种数据验证方法</li>
  19. <li>直列错误提示信息</li>
  20. <li>可扩展的数据验证方法</li>
  21. <li>使用内置的元数据或插件选项来指定您的验证规则</li>
  22. <li>优雅的交互设计</li>
  23. </ul>
  24. <p>官网:<a href="http://jqueryvalidation.org/" target="_blank">http://jqueryvalidation.org/</a>
  25. </p>
  26. </div>
  27. </div>
  28. </div>
  29. </div>
  30. <div class="row">
  31. <div class="col-sm-6">
  32. <div class="ibox float-e-margins">
  33. <div class="ibox-title">
  34. <h5>简单示例</h5>
  35. </div>
  36. <div class="ibox-content">
  37. <form class="form-horizontal m-t" id="commentForm">
  38. <div class="form-group">
  39. <label class="col-sm-3 control-label">姓名:</label>
  40. <div class="col-sm-8">
  41. <input id="cname" name="name" minlength="2" type="text" class="form-control" required>
  42. </div>
  43. </div>
  44. <div class="form-group">
  45. <label class="col-sm-3 control-label">E-mail:</label>
  46. <div class="col-sm-8">
  47. <input id="cemail" type="email" class="form-control" name="email" required>
  48. </div>
  49. </div>
  50. <div class="form-group">
  51. <label class="col-sm-3 control-label">网站:</label>
  52. <div class="col-sm-8">
  53. <input id="curl" type="url" class="form-control" name="url">
  54. </div>
  55. </div>
  56. <div class="form-group">
  57. <label class="col-sm-3 control-label">说明:</label>
  58. <div class="col-sm-8">
  59. <textarea id="ccomment" name="comment" class="form-control" required></textarea>
  60. </div>
  61. </div>
  62. <div class="form-group">
  63. <div class="col-sm-4 col-sm-offset-3">
  64. <button class="btn btn-primary" type="submit">提交</button>
  65. </div>
  66. </div>
  67. </form>
  68. </div>
  69. </div>
  70. <div class="ibox float-e-margins">
  71. <div class="ibox-content">
  72. <p class="m-t">更多示例请访问官方示例页面:<a href="http://jqueryvalidation.org/files/demo/" target="_blank">查看</a>
  73. </p>
  74. <p>中文API可参考:<a href="http://doc.ruoyi.vip/ruoyi/document/zjwd.html#jquery-validate" target="_blank">http://doc.ruoyi.vip/ruoyi/document/zjwd.html#jquery-validate</a>
  75. </p>
  76. </div>
  77. </div>
  78. </div>
  79. <div class="col-sm-6">
  80. <div class="ibox float-e-margins">
  81. <div class="ibox-title">
  82. <h5>完整验证表单</h5>
  83. </div>
  84. <div class="ibox-content">
  85. <form class="form-horizontal m-t" id="signupForm">
  86. <div class="form-group">
  87. <label class="col-sm-3 control-label">姓氏:</label>
  88. <div class="col-sm-8">
  89. <input id="firstname" name="firstname" class="form-control" type="text">
  90. <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 这里写点提示的内容</span>
  91. </div>
  92. </div>
  93. <div class="form-group">
  94. <label class="col-sm-3 control-label">名字:</label>
  95. <div class="col-sm-8">
  96. <input id="lastname" name="lastname" class="form-control" type="text" required>
  97. </div>
  98. </div>
  99. <div class="form-group">
  100. <label class="col-sm-3 control-label">用户名:</label>
  101. <div class="col-sm-8">
  102. <input id="username" name="username" class="form-control" type="text" required>
  103. </div>
  104. </div>
  105. <div class="form-group">
  106. <label class="col-sm-3 control-label">密码:</label>
  107. <div class="col-sm-8">
  108. <input id="password" name="password" class="form-control" type="password">
  109. </div>
  110. </div>
  111. <div class="form-group">
  112. <label class="col-sm-3 control-label">确认密码:</label>
  113. <div class="col-sm-8">
  114. <input id="confirm_password" name="confirm_password" class="form-control" type="password">
  115. <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 请再次输入您的密码</span>
  116. </div>
  117. </div>
  118. <div class="form-group">
  119. <label class="col-sm-3 control-label">E-mail:</label>
  120. <div class="col-sm-8">
  121. <input id="email" name="email" class="form-control" type="email">
  122. </div>
  123. </div>
  124. <div class="form-group">
  125. <div class="col-sm-8 col-sm-offset-3">
  126. <button class="btn btn-primary" type="submit">提交</button>
  127. </div>
  128. </div>
  129. </form>
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. <th:block th:include="include :: footer" />
  136. <script type="text/javascript">
  137. $(function(){
  138. $("#commentForm").validate();
  139. var icon = "<i class='fa fa-times-circle'></i> ";
  140. $("#signupForm").validate({
  141. rules: {
  142. firstname: "required",
  143. lastname: "required",
  144. username: {
  145. required: true,
  146. minlength: 2
  147. },
  148. password: {
  149. required: true,
  150. minlength: 5
  151. },
  152. confirm_password: {
  153. required: true,
  154. minlength: 5,
  155. equalTo: "#password"
  156. },
  157. email: {
  158. required: true,
  159. email: true
  160. }
  161. },
  162. messages: {
  163. firstname: icon + "请输入你的姓",
  164. lastname: icon + "请输入您的名字",
  165. username: {
  166. required: icon + "请输入您的用户名",
  167. minlength: icon + "用户名必须两个字符以上"
  168. },
  169. password: {
  170. required: icon + "请输入您的密码",
  171. minlength: icon + "密码必须5个字符以上"
  172. },
  173. confirm_password: {
  174. required: icon + "请再次输入密码",
  175. minlength: icon + "密码必须5个字符以上",
  176. equalTo: icon + "两次输入的密码不一致"
  177. },
  178. email: icon + "请输入您的E-mail"
  179. }
  180. });
  181. $("#username").focus(function () {
  182. var firstname = $("#firstname").val();
  183. var lastname = $("#lastname").val();
  184. if (firstname && lastname && !this.value) {
  185. this.value = firstname + "." + lastname;
  186. }
  187. });
  188. });
  189. </script>
  190. </body>
  191. </html>