Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery validation plugin - TypeError: $(...).validate is not a function

My script throw errors:

TypeError: jQuery.validator is undefined additional-methods.js:20 TypeError: $(...).validate is not a function index.php:115

Probably, I have mistake in jQuery code.

<head>
<script type="text/javascript" src="js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>
</head>
<body>
            <form id="registerForm" method="post" action="logrej.php">
            <input name="login" type="text"/>
            <input name="nick" type="text"/>
            <input type="password" id="passw" name="password"/>
            <input type="password" name="retype" />
            <input type="submit" value="Zarejestruj!" />
            </form>
            <script>

                $("#registerForm").validate({
                    rules: {
                        login: {
                            required:true,
                            rangelenght: [4,20],
                            remote:"look.php"
                        },
                        nick : {
                            required:true,
                            rangelenght:[4,20],
                            remote:"look.php"
                        },
                        password: {
                            required:true,
                            rangelenght:[4.20]
                        },
                        retype: {
                            required:true,
                            equalTo:"#passw"
                        }
                    },
                    messages:{
                        login:{
                            required:"To pole jest wymagane!"
                        }
                    }
                })

            </script>
like image 515
jaksa Avatar asked Feb 07 '14 20:02

jaksa


8 Answers

You're not loading the validation plugin. You need:

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>

Put this before the line that loads the additional methods.

Also, you should get the additional methods from the CDN as well, rather than jquery.bassistance.de.

Other errors:

[4.20]

should be

[4,20]

and

rangelenght:

should be:

rangelength:
like image 133
Barmar Avatar answered Oct 20 '22 01:10

Barmar


For me problem solved by changing http://ajax... into https://ajax... (add an S to http)

https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js
like image 36
dragoweb Avatar answered Oct 20 '22 00:10

dragoweb


Include jquery.validate.js before additional-methods.js.

$.validate() method is defined there

like image 43
n1k1ch Avatar answered Oct 19 '22 23:10

n1k1ch


It looks like the JavaScript error your getting is probably being caused by

password: {
    required:true,
    rangelenght:[4.20]
},

As the [4.20] should be [4,20], which i'd guess is throwing off the validation code in additional-methods hence giving the type error's you posted.

Edit: As others have noted in the below comments rangelenght is also misspelled & jquery.validate.js library appears to be missing (assuming its not compiled in to one of your other assets)

like image 39
Carl Avatar answered Oct 20 '22 00:10

Carl


I had the same problem. I am using jquery-validation as an npm module and the fix for me was to require the module at the start of my js file:

require('jquery-validation');
like image 23
Little Brain Avatar answered Oct 20 '22 00:10

Little Brain


for me, the problem was from require('jquery-validation') i added in the begging of that js file which Validate method used which is necessary as an npm module

unfortunately, when web pack compiles the js files, they aren't in order, so that the validate method is before defining it! and the error comes

so better to use another js file for compiling this library or use local validate method file or even using CDN but in all cases make sure you attached jquery before

like image 31
Ali Avatar answered Oct 20 '22 00:10

Ali


You didn't include the base jQuery Validation library:

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>

Put that before the additional methods library. (BTW this is a hosted version, download your own if you want)

like image 38
Damien Black Avatar answered Oct 19 '22 23:10

Damien Black


"validator.min.js" You need to import this JS file after "jquery-3.4.1.min.js". For you version might change but this way has worked for me.

Step 1 : Your project link files or it might be CDN

Step 2 :

Put validator.min.js CDN link or project JS folder link.

That is all, hope it might helps you.

like image 21
AS Kayal Avatar answered Oct 19 '22 23:10

AS Kayal