Simple form validation using Jquery.
Embed the below js files:
http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js
Add below CSS:
.error { border: 1px solid #b94a48!important; background-color: #fee !important; }
Script:
// When the browser is ready...
$(function() {
// Setup form validation on the #register-form element
$("#register-form").validate({ //#register-form is form id
// Specify the validation rules
rules: {
firstname: "required", //firstname is corresponding input name
lastname: "required", //lastname: is corresponding input name
email: { //email is corresponding input name
required: true,
email: true
},
},
// Specify the validation error messages
messages: {
firstname: "Enter First Name",
lastname: "Enter Last Name",
email: "Enter Valid Email ID",
agree: "Please accept our policy"
},
submitHandler: function(form) {
form.submit();
}
});
});
Embed the below js files:
http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js
Add below CSS:
.error { border: 1px solid #b94a48!important; background-color: #fee !important; }
Script:
// When the browser is ready...
$(function() {
// Setup form validation on the #register-form element
$("#register-form").validate({ //#register-form is form id
// Specify the validation rules
rules: {
firstname: "required", //firstname is corresponding input name
lastname: "required", //lastname: is corresponding input name
email: { //email is corresponding input name
required: true,
email: true
},
},
// Specify the validation error messages
messages: {
firstname: "Enter First Name",
lastname: "Enter Last Name",
email: "Enter Valid Email ID",
agree: "Please accept our policy"
},
submitHandler: function(form) {
form.submit();
}
});
});