Martyn Ball Martyn Ball - 1 month ago 14
Javascript Question

jQuery Validate Script Error, Cannot read property call of undefined

I have looked everywhere online but can't figure this issue out. Simply trying to use addMethod to create custom validation checks. However I keep getting the following error!

As far as I can tell i'm including the required plugins!

Error:


jquery.validate.js:754 Uncaught TypeError: Cannot read property 'call'
of undefined. Exception occurred when checking element comments,
check the 'nourl' method.


Code:

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/jquery.validate.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.15.0/additional-methods.min.js"></script>

<div class="container">
<div class="row">
<div class="twelvecol">
<form id="form" method="" action="">
<div class="row">
<div class="twelvecol">
<label for="name">Name</label>
<input type="text" id="name" name="name">
</div>
</div>

<div class="row">
<div class="twelvecol">
<label for="comments">Comments</label>
<input type="text" id="comments" name="comments">
</div>
</div>
</form>
</div>
</div>

</div>

<script>
$(document).ready(function(){
$.validator.addMethod("nourl", function(value, element) {
console.log("hello");
return !/http\:\/\/|www\.|link\=|url\=/.test(value);
}, "No URL's" );

$("#form").validate({
rules: {
name: {
required: true
},
comments: {
nourl: true
}
},
messages: {
name: "Required Field",
comments: "No URL's"
}
});
});
</script>

Answer

Sorry for wasted post, this plugin doesn't work on jQuery v1.7.1.

Comments