JQuery Validate validates specific instances of rules written in controls

  • 2020-03-30 02:08:59
  • OfStack

Writes the validation rule to the control


<script src="../js/jquery.js" type="text/javascript"></script>
<script src="../js/jquery.validate.js" type="text/javascript"></script>
<script src="./js/jquery.metadata.js" type="text/javascript"></script>
$().ready(function() {
 $("#signupForm").validate();
});
<form id="signupForm" method="get" action="">
    <p>
        <label for="firstname">Firstname</label>
        <input id="firstname" name="firstname" class="required" />
    </p>
 <p>
  <label for="email">E-Mail</label>
  <input id="email" name="email" class="required email" />
 </p>
 <p>
  <label for="password">Password</label>
  <input id="password" name="password" type="password" class="{required:true,minlength:5}" />
 </p>
 <p>
  <label for="confirm_password"> Confirm password </label>
  <input id="confirm_password" name="confirm_password" type="password" class="{required:true,minlength:5,equalTo:'#password'}" />
 </p>
    <p>
        <input class="submit" type="submit" value="Submit"/>
    </p>
</form>

Tips:
To use class="{}", you must introduce a package: jquery.metadata.js

You can use the following method to modify the prompt content:
Class = "{required: true, minlength: 5, messages: {required: 'please enter the content'}}"

When using the equalTo keyword, the following must be enclosed in quotes, as follows:
Class = "{required: true, minlength: 5, equalTo: '# password'}"


Related articles: