Home >Backend Development >PHP Tutorial >jquery validata form validation DEMO

jquery validata form validation DEMO

WBOY
WBOYOriginal
2016-07-25 08:48:251184browse
  1. jQuery Validation Framework
  2. 6. List of built-in Validation methods (List of built-in Validation methods)
  3. [1] required( ) Return: Boolean
  4. Description: Make form elements mandatory to fill in (select).
  5. If the form element is empty (text input) or not selected (radio/checkbox) or an empty value is selected (select).
  6. Acts on text inputs, selects, checkboxes and radio buttons.
  7. When select provides an empty option, it forces the user to choose a non-empty option value.
  8. Js code
  9. $("#myform").validate({
  10. rules: {
  11. fruit: "required"
  12. }
  13. });
  14. [2] required( dependency-expression) Return: Boolean
  15. Parameter dependency- expression type: String An expression (String) in the form context. Whether the form elements need to be filled in depends on the expression returning one or more elements.
  16. Description: Make the form elements must be filled in (selected), depending on the return value of the parameter.
  17. Selection filters like #foo:checked, #foo:filled, #foo:visible will be frequently used in expressions.
  18. Js code
  19. $("#myform").validate({
  20. rules: {
  21. details: {
  22. required: "#other:checked"
  23. }
  24. }, debug:true
  25. });
  26. $("# other").click(function() {
  27. $("#details").valid();
  28. });
  29. [3] required( dependency-callback ) Return: Boolean
  30. Parameter dependency-callback Type: Callback The The return function takes the form element to be validated as its only parameter. When the callback function returns true, the form element is required.
  31. Description: Make the form elements must be filled in (selected), depending on the return value of the parameter.
  32. Selection filters like #foo:checked, #foo:filled, #foo:visible will be frequently used in expressions.
  33. Js code
  34. $("#myform").validate({
  35. rules: {
  36. age: {
  37. required: true,
  38. min: 3
  39. },
  40. parent: {
  41. required: function(element) {
  42. return $("#age").val() < 13;
  43. }
  44. }
  45. }
  46. });
  47. $("#age").blur(function() {
  48. $("#parent").valid ();
  49. });
  50. [4] remote( options ) Return: Boolean
  51. Parameter options Type: String, Options url (String) for requesting server-side resources. Or Options in the $.ajax() method.
  52. Description: Request server-side resource verification.
  53. The server-side resource obtains the key/value pair through $.ajax (XMLHttpRequest). If the response returns true, the form passes the verification.
  54. Js code
  55. $("#myform").validate({
  56. rules: {
  57. email: {
  58. required: true,
  59. email: true,
  60. remote: "check-email.php"
  61. }
  62. }
  63. } );
  64. [5] minlength( length ) Return: Boolean
  65. Parameter length Type: Integer The minimum number of characters required.
  66. Description: Make sure the form elements meet the given minimum number of characters.
  67. Too few characters are entered in the text input, not enough checkboxes are selected, and not enough options are selected in a select box. In these three cases, this method returns false.
  68. Js code
  69. $("#myform").validate({
  70. rules: {
  71. field: {
  72. required: true,
  73. minlength: 3
  74. }
  75. }
  76. });
  77. [6] maxlength( length ) Return: Boolean
  78. Parameter length Type: Integer The maximum number of characters allowed to be entered.
  79. Description: Make sure the text of the form element does not exceed the given maximum number of characters.
  80. Entering too many characters into the text input box (text input), selecting too many check boxes (check boxes), and not selecting too many options in a selection box (select). In these three cases, this method returns false.
  81. Js code
  82. $("#myform").validate({
  83. rules: {
  84. field: {
  85. required: true,
  86. maxlength: 4
  87. }
  88. }
  89. });
  90. [7] rangelength( range ) Return: Boolean
  91. Parameter range Type: Array The range of characters allowed to be entered.
  92. Description: Ensure that the number of text characters of the form element is within the given range.
  93. The number of characters entered in the text input box is not within the given range, the selected checkbox is not within the given range, and the option selected in a select box is not within the given range. In these three cases, this method returns false.
  94. Js code
  95. $("#myform").validate({
  96. rules: {
  97. field: {
  98. required: true,
  99. rangelength: [2, 6]
  100. }
  101. }
  102. });
  103. [8] min( value ) Returns: Boolean
  104. Parameter value type: Integer The minimum integer that needs to be input.
  105. Description: Ensure that the value of the form element is greater than or equal to the given minimum integer.
  106. This method is only valid in the text input box (text input).
  107. Js code
  108. $("#myform").validate({
  109. rules: {
  110. field: {
  111. required: true,
  112. min: 13
  113. }
  114. }
  115. });
  116. [9] max( value ) Return: Boolean
  117. Parameter value type: Integer The maximum integer given.
  118. Description: Ensure that the value of the form element is less than or equal to the given maximum integer.
  119. This method is only valid in the text input box (text input).
  120. Js code
  121. $("#myform").validate({
  122. rules: {
  123. field: {
  124. required: true,
  125. max: 23
  126. }
  127. }
  128. });
  129. [10] range( range ) Return: Boolean
  130. Parameter range type: Array The given integer range.
  131. Description: Ensure that the value of the form element is within the given range.
  132. This method is only valid in the text input box (text input).
  133. Js code
  134. $("#myform").validate({
  135. rules: {
  136. field: {
  137. required: true,
  138. range: [13, 23]
  139. }
  140. }
  141. });
  142. [11] email( ) returns: Boolean
  143. Description: Make sure the value of the form element is a valid email address.
  144. Returns true if the value is a valid email address. This method is only valid under text input box (text input).
  145. Js code
  146. $("#myform").validate({
  147. rules: {
  148. field: {
  149. required: true,
  150. email: true
  151. }
  152. }
  153. });
  154. [12] url( ) return :Boolean
  155. Description: Make sure the value of the form element is a valid URL address (http://www.mydomain.com).
  156. Returns true if the value is a valid url address. This method is only valid under text input box (text input).
  157. Js code
  158. $("#myform").validate({
  159. rules: {
  160. field: {
  161. required: true,
  162. url: true
  163. }
  164. }
  165. });
  166. [13] date( ) dateISO ( ) dateDE( ) Return: Boolean
  167. Description: Used to verify valid dates. The date formats verified by these three functions are (mm/dd/yyyy), (yyyy-mm-dd,yyyy/mm/dd), and (mm.dd.yyyy) respectively.
  168. Js code
  169. $("#myform").validate({
  170. rules: {
  171. field: {
  172. required: true,
  173. date: true
  174. /*dateISO: true
  175. dateDE: true*/
  176. }
  177. }
  178. });
  179. [14] number( ) numberDE() Return: Boolean
  180. Description: Used to verify decimals. The decimal point of number() is a dot ( . ), and the decimal point of numberDE() is a comma ( , ).
  181. Js code
  182. $("#myform").validate({
  183. rules: {
  184. field: {
  185. required: true,
  186. number: true
  187. //numberDE: true
  188. }
  189. }
  190. });
  191. [ 15] digits() Return: Boolean
  192. Description: Make sure the value in the text box is a number.
  193. Js code
  194. $("#myform").validate({
  195. rules: {
  196. field: {
  197. required: true,
  198. digits: true
  199. }
  200. }
  201. });
  202. [16] digits() return :Boolean
  203. Description: Make sure the value in the text box is a number.
  204. Js code
  205. $("#myform").validate({
  206. rules: {
  207. field: {
  208. required: true,
  209. digits: true
  210. }
  211. }
  212. });
  213. [17] accept( [extension ] ) Return: Boolean
  214. Parameter extension (Optional) Type: String Allowed file suffix name, separated by "|" or ",". The default is "png|jpe?g|gif"
  215. Description: Ensure that the form element receives the file with the given file extension. If no parameters are specified, only images are allowed (png, jpeg, gif).
  216. Js code
  217. $("#myform").validate({
  218. rules: {
  219. field: {
  220. required: true,
  221. accept: "xls|csv"
  222. }
  223. }
  224. });
  225. [18] equalTo( other ) Returns: Boolean
  226. Parameter other Type: Selector Another form element to be compared with the current value.
  227. Description: Make sure the values ​​of the two form elements are consistent.
  228. Js code
  229. $("#myform").validate({
  230. rules: {
  231. password: "required",
  232. password_again: {
  233. equalTo: "#password"
  234. }
  235. }
  236. });
Copy Code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn