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)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1255
29
C# Tutorial
1228
24
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.

How do you handle exceptions effectively in PHP (try, catch, finally, throw)? How do you handle exceptions effectively in PHP (try, catch, finally, throw)? Apr 05, 2025 am 12:03 AM

In PHP, exception handling is achieved through the try, catch, finally, and throw keywords. 1) The try block surrounds the code that may throw exceptions; 2) The catch block handles exceptions; 3) Finally block ensures that the code is always executed; 4) throw is used to manually throw exceptions. These mechanisms help improve the robustness and maintainability of your code.

Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Apr 08, 2025 am 12:03 AM

There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

What is the difference between include, require, include_once, require_once? What is the difference between include, require, include_once, require_once? Apr 05, 2025 am 12:07 AM

In PHP, the difference between include, require, include_once, require_once is: 1) include generates a warning and continues to execute, 2) require generates a fatal error and stops execution, 3) include_once and require_once prevent repeated inclusions. The choice of these functions depends on the importance of the file and whether it is necessary to prevent duplicate inclusion. Rational use can improve the readability and maintainability of the code.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? Apr 09, 2025 am 12:09 AM

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles