Introduction to jquery.validate form validation plug-in
This article mainly introduces the use of jquery.validate form verification plug-in in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.
Today we will talk about form validation. Some people say that it is very troublesome to use regular expressions when performing form validation. Now I will introduce to you the form validation plug-in: jquery.validate.min. js
It is used in conjunction with jquery. It is very convenient to use it. You only need to write the verification rules and error fields.
our common verification rules are the following:
(1) Required: TRUE must lose field
(2) Email: True must enter the correct format of email
# #(3)date:true You must enter the date in the correct format
(4)dateISO:true You must enter the date in the correct format (ISO)
(5)digits:true You must enter an integer
(6)equalTo :"#pass" The input value must be the same as #pass
(7)maxlength:5 Enter a string with a maximum length of 5
(8)minlength:10 Enter a string with a minimum length of 10
( 9)rangelength:[5,10] The input length must be between 5 and 10
(10)range:[5,10] The input value must be between 5 and 10
(11)max: 5 The input value cannot be greater than 5
(12)min:10 The input value cannot be less than 10
Then just write the prompt field, but you don’t need to write it because it has an English prompt field. Here is Please take a look at the following code:
Before we use the plug-in, it is indispensable to introduce the jquery file and plug-in
<script src="jquery-1.9.1.js"></script> <script src="jquery.validate.min.js"></script>
Then let’s take a look Let’s take a look at the html code
<form action="" id="mgForm"> //写表单验证比不缺少的是我们的form标签 <p> //关于用户名的布局 <label for="user">username:</label> <input type="text" name="username" id="user"> </p> <p>//关于密码的布局 <label for="pass">password:</label> <input type="text" name="password" id="pass"> </p> <p>//重置密码 <label for="pass1">form-password:</label> <input type="text" name="password1" id="pass1"> </p> <p>//年龄 <label for="age">age:</label> <input type="text" name="age" id="age"> </p> <p>//email <label for="email">email:</label> <input type="text" name="email" id="email"> </p> <input type="submit" value="提交"> //我们在提交数据时提交的按钮应该为submit类型的 </form>
Then let’s take a look at the js code
$(function () { $("#mgForm").validate({ rules:{//写入文本框中的限制条件 username:{ //指的是input中name的名字 required:true,//不能为空 minlength:6,//最短为6个 maxlength:10//最长为10个 }, age:{ // range:[18,80] //年龄范围为18-80 required:true, //不能为空 }, password:{ required:true,//必填 rangelength:[2,6] //长度为2-6 }, password1:{ equalTo:"#pass" //重置密码必须与#pass中的密码保持一致 }, email:{ email:true //email保证格式正确 } }, messages:{//提示信息 username:{ //用户名 required:"*此项必填", minlength:"*用户名最小是6位", maxlength:"*用户名最大是10位" }, age:{//年龄 range:"*年龄必须在18-80之间" PostCode:"错误" }, password:{//密码 required:"*必填", rangelength:"2-6" }, password1:{//重置密码 equalTo:"*密码不一致" }, email:{//邮箱格式 email:"*邮箱格式不正确" } }, submitHanfler:function () {//如果全部验证正确就弹出弹窗 alert("全部通过") }, errorClass:"wrong",//给错误字段添加wrong样式 ignore:"#pass1",//忽略密码不一 errorElement:"p",//错误信息单独显示一行 focusInvalid:true,//提交表单后,未通过验证的表单(第一个或提交之 前获得焦点的未通过验证的表单)会获得焦点 focusCleanup:true,// 当未通过验证的元素获得焦点时,并移除错误提示 highlight:function (element,errorClass) {//在信息错误时会出现一闪的效果 $(element).addClass(errorClass); $(element).fadeOut().fadeIn() } }); $.validator.addMethod("PostCode",function () { //此外,我们还可自定义样式 var reg=/^[0-9]{6}$/; return reg.test(value) },"邮编输入不正确"); });
Today’s table Have you learned how to use the verification plug-in?
Related recommendations:
Example introduction to regular expression form validation
Example detailed explanation of jQuery's form validation function
The above is the detailed content of Introduction to jquery.validate form validation plug-in. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Users may have seen the term wapi when using the Internet, but for some people they definitely don’t know what wapi is. The following is a detailed introduction to help those who don’t know to understand. What is wapi: Answer: wapi is the infrastructure for wireless LAN authentication and confidentiality. This is like functions such as infrared and Bluetooth, which are generally covered near places such as office buildings. Basically they are owned by a small department, so the scope of this function is only a few kilometers. Related introduction to wapi: 1. Wapi is a transmission protocol in wireless LAN. 2. This technology can avoid the problems of narrow-band communication and enable better communication. 3. Only one code is needed to transmit the signal

PyCharm is a powerful and popular Python integrated development environment (IDE) that provides a wealth of functions and tools so that developers can write code more efficiently. The plug-in mechanism of PyCharm is a powerful tool for extending its functions. By installing different plug-ins, various functions and customized features can be added to PyCharm. Therefore, it is crucial for newbies to PyCharm to understand and be proficient in installing plug-ins. This article will give you a detailed introduction to the complete installation of PyCharm plug-in.
![Error loading plugin in Illustrator [Fixed]](https://img.php.cn/upload/article/000/465/014/170831522770626.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
When launching Adobe Illustrator, does a message about an error loading the plug-in pop up? Some Illustrator users have encountered this error when opening the application. The message is followed by a list of problematic plugins. This error message indicates that there is a problem with the installed plug-in, but it may also be caused by other reasons such as a damaged Visual C++ DLL file or a damaged preference file. If you encounter this error, we will guide you in this article to fix the problem, so continue reading below. Error loading plug-in in Illustrator If you receive an "Error loading plug-in" error message when trying to launch Adobe Illustrator, you can use the following: As an administrator

Pubg, also known as PlayerUnknown's Battlegrounds, is a very classic shooting battle royale game that has attracted a lot of players since its popularity in 2016. After the recent launch of win11 system, many players want to play it on win11. Let's follow the editor to see if win11 can play pubg. Can win11 play pubg? Answer: Win11 can play pubg. 1. At the beginning of win11, because win11 needed to enable tpm, many players were banned from pubg. 2. However, based on player feedback, Blue Hole has solved this problem, and now you can play pubg normally in win11. 3. If you meet a pub

When users use the Edge browser, they may add some plug-ins to meet more of their needs. But when adding a plug-in, it shows that this plug-in is not supported. How to solve this problem? Today, the editor will share with you three solutions. Come and try it. Method 1: Try using another browser. Method 2: The Flash Player on the browser may be out of date or missing, causing the plug-in to be unsupported. You can download the latest version from the official website. Method 3: Press the "Ctrl+Shift+Delete" keys at the same time. Click "Clear Data" and reopen the browser.

What is the Chrome plug-in extension installation directory? Under normal circumstances, the default installation directory of Chrome plug-in extensions is as follows: 1. The default installation directory location of chrome plug-ins in windowsxp: C:\DocumentsandSettings\username\LocalSettings\ApplicationData\Google\Chrome\UserData\Default\Extensions2. chrome in windows7 The default installation directory location of the plug-in: C:\Users\username\AppData\Local\Google\Chrome\User

i5 is a series of processors owned by Intel. It has various versions of the 11th generation i5, and each generation has different performance. Therefore, whether the i5 processor can install win11 depends on which generation of the processor it is. Let’s follow the editor to learn about it separately. Can i5 processor be installed with win11: Answer: i5 processor can be installed with win11. 1. The eighth-generation and subsequent i51, eighth-generation and subsequent i5 processors can meet Microsoft’s minimum configuration requirements. 2. Therefore, we only need to enter the Microsoft website and download a "Win11 Installation Assistant" 3. After the download is completed, run the installation assistant and follow the prompts to install Win11. 2. i51 before the eighth generation and after the eighth generation

Does PyCharm Community Edition support enough plugins? Need specific code examples As the Python language becomes more and more widely used in the field of software development, PyCharm, as a professional Python integrated development environment (IDE), is favored by developers. PyCharm is divided into two versions: professional version and community version. The community version is provided for free, but its plug-in support is limited compared to the professional version. So the question is, does PyCharm Community Edition support enough plug-ins? This article will use specific code examples to
