A simple jQuery form validation script [closed]
You can simply use the jQuery Validate plugin as follows.
jQuery:
$(document).ready(function () { $('#myform').validate({ // initialize the plugin rules: { field1: { required: true, email: true }, field2: { required: true, minlength: 5 } } });});
HTML:
<form id="myform"> <input type="text" name="field1" /> <input type="text" name="field2" /> <input type="submit" /></form>
DEMO: http://jsfiddle.net/xs5vrrso/
Options: http://jqueryvalidation.org/validate
Methods: http://jqueryvalidation.org/category/plugin/
Standard Rules: http://jqueryvalidation.org/category/methods/
Optional Rules available with the additional-methods.js
file:
maxWordsminWordsrangeWordsletterswithbasicpuncalphanumericlettersonlynowhitespaceziprangezipcodeUSintegervinUSdateITAdateNLtimetime12hphoneUSphoneUKmobileUKphonesUKpostcodeUKstrippedminlengthemail2 (optional TLD)url2 (optional TLD)creditcardtypesipv4ipv6patternrequire_from_groupskip_or_fill_minimumacceptextension
you can use jquery validator for that but you need to add jquery.validate.js and jquery.form.js file for that. after including validator file define your validation something like this.
<script type="text/javascript">$(document).ready(function(){ $("#formID").validate({ rules :{ "data[User][name]" : { required : true } }, messages :{ "data[User][name]" : { required : 'Enter username' } } });});</script>
You can see required : true
same there is many more property like for email you can define email : true
for number number : true