简体   繁体   中英

Validate form with Jquery validation

I want to validate my form, but I had this error :

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

I included the js files validation jquery-validate.min.js and jquery-validate.js.Thanks

index.html

<form id="form1">
<label for="phone">First Name</label>
<input type="text" name="name" required />
<input type="button" id="btn" value="ok" />
</form>

file.js

$(document).ready(function (){    
$("#form1").validate({
    rules: {
        name: "required"
    },
    messages: {
        name: "Please specify your name"

    }
})

$('#btn').click(function() {
    $("#form1").valid();
});

});

Check this and note how the scripts are included:

 $(document).ready(function (){ $("#form1").validate({ rules: { name: "required" }, messages: { name: "Please specify your name" } }); $('#btn').click(function() { $("#form1").valid(); }); }); 
 #form1 label.error { color: #FB3A3A; display: block; margin: 10px; padding: 0; text-align: left; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.13.1/jquery.validate.min.js"></script> <form id="form1"> <label for="name">First Name</label> <input type="text" name="name" required /> <input type="button" id="btn" value="ok" /> </form> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM