Guardian

by Michael Eisenbraun

Guardian is a all-purpose form validation jQuery plugin. It was designed to be flexible and easy to extend to meet any need.

Example 1: Basic Form

HTML

 
					

JavaScript

					$('#example1').guardian();
				

Example 2: Error messaging

HTML

 
					

JavaScript

					$('#example1').guardian();
				

Example 3: Additional Input Types and Patterns

HTML

 
					

JavaScript

					$('#example3').guardian();
				

Example 4: Extending Guardian

HTML

 
					

JavaScript

 					
					$('#example4').guardian({
					    //Display the number of invalid fields on submit
					    failure: function() {
							this.$el.prepend('There are '+this.getInvalid().length+' invalid fields'); 
						},
                        //Disable inputs validating on blur 
						extend: function() {
							var $this = this; 
							$this.$el.off('change blur', ':input', $this.onBlur); 
						}
					});