Skip to content

Instantly share code, notes, and snippets.

@jrdmcgr
Last active December 16, 2015 12:39
Show Gist options
  • Save jrdmcgr/5435829 to your computer and use it in GitHub Desktop.
Save jrdmcgr/5435829 to your computer and use it in GitHub Desktop.
How to Extend Validity (http://validity.thatscaptaintoyou.com/)
//
// How to Extend Validity
//
// Setup validity and get the private validation function.
$.validity.setup({debugPrivates: true})
var validate = $.validity.__private.validate
// Add our message
$.validity.messages.myCustomValidationMessage = 'You fail.'
// Write a custom validation method
$.fn.myCustomValidation = function (msg) {
return validate(
this,
function(obj) {
// do some custom stuff here.
},
msg || $.validity.messages.myCustomValidationMessage
);
}
// Use this elsewhere in your code like any of the other validation methods.
$.validity.start()
$('.some-form-fields').myCustomValidation()
var results = $.validity.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment