Skip to content

Instantly share code, notes, and snippets.

@snikch
Created November 23, 2010 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snikch/711376 to your computer and use it in GitHub Desktop.
Save snikch/711376 to your computer and use it in GitHub Desktop.
A spec for a light weight jQuery validation plugin with schemas not classes
* Must NOT use class="required" validation
* Must use Javascript objects for validation
var schema = {
options : {
'bubble' : true, // Bubble validation checks to all elements, if false will stop on fail
'blur' : false, // Will not call the validate method on the inputs
'auto' : false, // Will not attempt to apply to all forms, just ID matched forms
'decorator' : 'inline' // Defaults to supplied decorator, but a decorator can be supplied
},
// Create custom rules / defaults. These will automagically match input names
rules : {
name : {
minlen: {3, 'Name must be at least 3 characters'},
maxlen: {100, 'Name must not be more than 3 characters'}
},
twitter : function(val){
.... return true if a valid twitter name (query api)
}
},
'#newarticleform' : {
// Use a custom twitter validation rule, must have been passed
twittername : {{'twitter', 'Please select a valid twitter username'}},
othertwittername : {'twitter'} // use default message
}
}
* Use HTML5 element types to add validation rules (email, url, date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment