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() {
<form id="signupForm" method="get" action="">
        <label for="firstname">Firstname</label>
        <input id="firstname" name="firstname" class="required" />
  <label for="email">E-Mail</label>
  <input id="email" name="email" class="required email" />
  <label for="password">Password</label>
  <input id="password" name="password" type="password" class="{required:true,minlength:5}" />
  <label for="confirm_password"> Confirm password </label>
  <input id="confirm_password" name="confirm_password" type="password" class="{required:true,minlength:5,equalTo:'#password'}" />
        <input class="submit" type="submit" value="Submit"/>

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: