Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )
premise:
validate plugin is written on the basis of Jquery, if the rules call plug-in to be successful, we must first introducing the download link :( widget directly linked to my csdn)
The format used is: (must be written in this format, otherwise it will not be used)
表单jQuery对象.validate({
rules:{
表单元素name值1:"规则1",
表单元素name值2:{
规则名称:规则值,
规则名称:规则值,
}
},
messages:{
表单元素name值1:"提示1",
表单元素name值2:{
规则名称:"提示2_1",
规则名称:"提示2_2",
}
}
})
Common rules:
Small case:
Core code, do not forget to pay attention to the reference.
<script type="text/javascript" src="../js/jquery-3.3.1.js"></script> <script type="text/javascript" src="../js/jquery.validate.js"></script>
$(function(){
$("#myform").validate({
rules:{
username:"required",
password:{
required:true,
minlength:8,
maxlength:16
}
},
messages:{
username:"用户名必填",
password:{
required:"密码不能为空",
minlength:"密码的最小长度是8",
maxlength:"密码的最长长度是16"
}
}
})
})
html code:
<form name="myform" id="myform" method="post" action="test.html">
用户名<input type="text" name="username"/><br/>
密码<input type="text" name="password"/><br/>
<input type="submit"/>
</form>
Note: Plug-references retrieved name is the name of the calling.