var self = this;
$(document).ready(function() {
$("#myForm").validate({
rules: {
'name': { required: true,
},
'email': {
required: true,
}
},
messages: {
'name': {
required: "Name is required"
},
'email': {
required: "Email is required",
}
}
});
$(".submit").click(function() {
if (!$("#myForm").valid())
alert("Form has validation errors. Cannot submit!!");
else {
alert("Form can be submitted!!");
}
});
});
.error {
color: red;
}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script><scriptsrc="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.js"></script><formmethod="post"id="myForm"><inputtype="text"name="name"placeholder="Name :"data-required="true"data-type="Name"><inputtype="text"name="email"placeholder="Email:"data-required="true"data-type="Email"><inputtype="text"name="phone"placeholder="Phone Number:"data-required="true"data-type="Phone"><select><optionvalue=""disabledselected>College Name:</option><option>College 1</option><option>College 2</option><option>College 3</option><option>College 4</option><option>College 5</option><option>College 6</option></select><select><optionvalue=""disabledselected>Enquiry Type:</option><option>MD/MS Coaching</option><option>MDS Coaching</option><option>DNB Coaching</option></select><textarea>Message</textarea><buttonclass="btn btn-info submit">Submit</button></form>
Post a Comment for "How To Add Form Validation In Html?"