search
HomeBackend DevelopmentPHP Tutorialjquery validata form validation DEMO

  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() }
  43. }
  44. }
  45. });
  46. $("#age").blur(function() {
  47. $("#parent").valid ();
  48. });
  49. [4] remote( options ) Return: Boolean
  50. Parameter options Type: String, Options url (String) for requesting server-side resources. Or Options in the $.ajax() method.
  51. Description: Request server-side resource verification.
  52. The server-side resource obtains the key/value pair through $.ajax (XMLHttpRequest). If the response returns true, the form passes the verification.
  53. Js code
  54. $("#myform").validate({
  55. rules: {
  56. email: {
  57. required: true,
  58. email: true,
  59. remote: "check-email.php"
  60. }
  61. }
  62. } );
  63. [5] minlength( length ) Return: Boolean
  64. Parameter length Type: Integer The minimum number of characters required.
  65. Description: Make sure the form elements meet the given minimum number of characters.
  66. 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.
  67. Js code
  68. $("#myform").validate({
  69. rules: {
  70. field: {
  71. required: true,
  72. minlength: 3
  73. }
  74. }
  75. });
  76. [6] maxlength( length ) Return: Boolean
  77. Parameter length Type: Integer The maximum number of characters allowed to be entered.
  78. Description: Make sure the text of the form element does not exceed the given maximum number of characters.
  79. 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.
  80. Js code
  81. $("#myform").validate({
  82. rules: {
  83. field: {
  84. required: true,
  85. maxlength: 4
  86. }
  87. }
  88. });
  89. [7] rangelength( range ) Return: Boolean
  90. Parameter range Type: Array The range of characters allowed to be entered.
  91. Description: Ensure that the number of text characters of the form element is within the given range.
  92. 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.
  93. Js code
  94. $("#myform").validate({
  95. rules: {
  96. field: {
  97. required: true,
  98. rangelength: [2, 6]
  99. }
  100. }
  101. });
  102. [8] min( value ) Returns: Boolean
  103. Parameter value type: Integer The minimum integer that needs to be input.
  104. Description: Ensure that the value of the form element is greater than or equal to the given minimum integer.
  105. This method is only valid in the text input box (text input).
  106. Js code
  107. $("#myform").validate({
  108. rules: {
  109. field: {
  110. required: true,
  111. min: 13
  112. }
  113. }
  114. });
  115. [9] max( value ) Return: Boolean
  116. Parameter value type: Integer The maximum integer given.
  117. Description: Ensure that the value of the form element is less than or equal to the given maximum integer.
  118. This method is only valid in the text input box (text input).
  119. Js code
  120. $("#myform").validate({
  121. rules: {
  122. field: {
  123. required: true,
  124. max: 23
  125. }
  126. }
  127. });
  128. [10] range( range ) Return: Boolean
  129. Parameter range type: Array The given integer range.
  130. Description: Ensure that the value of the form element is within the given range.
  131. This method is only valid in the text input box (text input).
  132. Js code
  133. $("#myform").validate({
  134. rules: {
  135. field: {
  136. required: true,
  137. range: [13, 23]
  138. }
  139. }
  140. });
  141. [11] email( ) returns: Boolean
  142. Description: Make sure the value of the form element is a valid email address.
  143. Returns true if the value is a valid email address. This method is only valid under text input box (text input).
  144. Js code
  145. $("#myform").validate({
  146. rules: {
  147. field: {
  148. required: true,
  149. email: true
  150. }
  151. }
  152. });
  153. [12] url( ) return :Boolean
  154. Description: Make sure the value of the form element is a valid URL address (http://www.mydomain.com).
  155. Returns true if the value is a valid url address. This method is only valid under text input box (text input).
  156. Js code
  157. $("#myform").validate({
  158. rules: {
  159. field: {
  160. required: true,
  161. url: true
  162. }
  163. }
  164. });
  165. [13] date( ) dateISO ( ) dateDE( ) Return: Boolean
  166. 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.
  167. Js code
  168. $("#myform").validate({
  169. rules: {
  170. field: {
  171. required: true,
  172. date: true
  173. /*dateISO: true
  174. dateDE: true*/
  175. }
  176. }
  177. });
  178. [14] number( ) numberDE() Return: Boolean
  179. Description: Used to verify decimals. The decimal point of number() is a dot ( . ), and the decimal point of numberDE() is a comma ( , ).
  180. Js code
  181. $("#myform").validate({
  182. rules: {
  183. field: {
  184. required: true,
  185. number: true
  186. //numberDE: true
  187. }
  188. }
  189. });
  190. [ 15] digits() Return: Boolean
  191. Description: Make sure the value in the text box is a number.
  192. Js code
  193. $("#myform").validate({
  194. rules: {
  195. field: {
  196. required: true,
  197. digits: true
  198. }
  199. }
  200. });
  201. [16] digits() return :Boolean
  202. Description: Make sure the value in the text box is a number.
  203. Js code
  204. $("#myform").validate({
  205. rules: {
  206. field: {
  207. required: true,
  208. digits: true
  209. }
  210. }
  211. });
  212. [17] accept( [extension ] ) Return: Boolean
  213. Parameter extension (Optional) Type: String Allowed file suffix name, separated by "|" or ",". The default is "png|jpe?g|gif"
  214. 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).
  215. Js code
  216. $("#myform").validate({
  217. rules: {
  218. field: {
  219. required: true,
  220. accept: "xls|csv"
  221. }
  222. }
  223. });
  224. [18] equalTo( other ) Returns: Boolean
  225. Parameter other Type: Selector Another form element to be compared with the current value.
  226. Description: Make sure the values ​​of the two form elements are consistent.
  227. Js code
  228. $("#myform").validate({
  229. rules: {
  230. password: "required",
  231. password_again: {
  232. equalTo: "#password"
  233. }
  234. }
  235. });
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
How do you create and use an interface in PHP?How do you create and use an interface in PHP?Apr 30, 2025 pm 03:40 PM

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

What is the difference between crypt() and password_hash()?What is the difference between crypt() and password_hash()?Apr 30, 2025 pm 03:39 PM

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

How can you prevent Cross-Site Scripting (XSS) in PHP?How can you prevent Cross-Site Scripting (XSS) in PHP?Apr 30, 2025 pm 03:38 PM

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

What is autoloading in PHP?What is autoloading in PHP?Apr 30, 2025 pm 03:37 PM

Autoloading in PHP automatically loads class files when needed, improving performance by reducing memory use and enhancing code organization. Best practices include using PSR-4 and organizing code effectively.

What are PHP streams?What are PHP streams?Apr 30, 2025 pm 03:36 PM

PHP streams unify handling of resources like files, network sockets, and compression formats via a consistent API, abstracting complexity and enhancing code flexibility and efficiency.

What is the maximum size of a file that can be uploaded using PHP ?What is the maximum size of a file that can be uploaded using PHP ?Apr 30, 2025 pm 03:35 PM

The article discusses managing file upload sizes in PHP, focusing on the default limit of 2MB and how to increase it by modifying php.ini settings.

What is Nullable types in PHP ?What is Nullable types in PHP ?Apr 30, 2025 pm 03:34 PM

The article discusses nullable types in PHP, introduced in PHP 7.1, allowing variables or parameters to be either a specified type or null. It highlights benefits like improved readability, type safety, and explicit intent, and explains how to declar

What is the difference between the unset() and unlink() functions ?What is the difference between the unset() and unlink() functions ?Apr 30, 2025 pm 03:33 PM

The article discusses the differences between unset() and unlink() functions in programming, focusing on their purposes and use cases. Unset() removes variables from memory, while unlink() deletes files from the filesystem. Both are crucial for effec

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor