最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Validate is not a function - Stack Overflow

programmeradmin2浏览0评论

I am trying to validate a simple form. But I keep getting this error

Uncaught TypeError: $(...).validate is not a function

Here is my html file with form:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Cohorts</title>


  </head>
  <body>
    <script src=".validate/1.15.0/jquery.validate.min.js"></script>
    <script src="trunk/dev/validation.js"></script>

    <form id="register-form" class="form-horizontal" name="form" ng-submit="addCohort()">

      <div class="form-group">

        <label class="control-label col-xs-3">Name:</label>

        <input name="email" placeholder="Email Address" type="text" ng-model="formCohort.firstname">

        <input class = "btn-btn-primary" id="submit-button"  type="submit" value="Sigin up">
      </div>

    </form>
  </body>
</html>

Here is my validation.

$(function () {
  $("#register-form").validate({
    rules:{
      email:{
        required: true,
        email: true

      }
    }
  });

});

Here is the error in my console:

What am I doing wrong?

Thank you!

I am trying to validate a simple form. But I keep getting this error

Uncaught TypeError: $(...).validate is not a function

Here is my html file with form:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Cohorts</title>


  </head>
  <body>
    <script src="http://ajax.aspnetcdn./ajax/jquery.validate/1.15.0/jquery.validate.min.js"></script>
    <script src="trunk/dev/validation.js"></script>

    <form id="register-form" class="form-horizontal" name="form" ng-submit="addCohort()">

      <div class="form-group">

        <label class="control-label col-xs-3">Name:</label>

        <input name="email" placeholder="Email Address" type="text" ng-model="formCohort.firstname">

        <input class = "btn-btn-primary" id="submit-button"  type="submit" value="Sigin up">
      </div>

    </form>
  </body>
</html>

Here is my validation.

$(function () {
  $("#register-form").validate({
    rules:{
      email:{
        required: true,
        email: true

      }
    }
  });

});

Here is the error in my console:

What am I doing wrong?

Thank you!

Share Improve this question edited Jun 8, 2016 at 20:28 user3599415 asked Jun 8, 2016 at 20:22 user3599415user3599415 2833 gold badges6 silver badges19 bronze badges 2
  • You've included the validate library twice. Delete one of the files, I would suggest that you keep the .min version – Rory McCrossan Commented Jun 8, 2016 at 20:25
  • @RoryMcCrossan I removed it and it still gave me the same error – user3599415 Commented Jun 8, 2016 at 20:27
Add a ment  | 

1 Answer 1

Reset to default 5

You should first include the jQuery library
and than your validate plugin

<script src="https://code.jquery./jquery-2.1.4.js"></script>
<script src="http://ajax.aspnetcdn./ajax/jquery.validate/1.15.0/jquery.validate.min.js"></script>
<script src="trunk/dev/validation.js"></script>

P.S: make sure you have only one validate plugin!

Additionally, I'd suggest you to include your <script> tags right before the closing </body> tag.

<form id="register-form">
  <input name="email" placeholder="Email Address" type="text">
  <input type="submit" value="Sigin up">
</form>


<script src="https://code.jquery./jquery-3.1.0.js"></script>
<script src="https://ajax.aspnetcdn./ajax/jquery.validate/1.15.0/jquery.validate.min.js"></script>
<script>
  jQuery(function($) {
  
    $("#register-form").validate({
      rules: {
        email: {
          required: true,
          email: true
        }
      }
    });
    
  });
</script>

发布评论

评论列表(0)

  1. 暂无评论