Home Backend Development PHP Tutorial jquery validata form validation DEMO

jquery validata form validation DEMO

Jul 25, 2016 am 08:48 AM

  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 of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

What are Enumerations (Enums) in PHP 8.1? What are Enumerations (Enums) in PHP 8.1? Apr 03, 2025 am 12:05 AM

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

See all articles