Skip to content

Instantly share code, notes, and snippets.

@dshook
Created February 17, 2015 21:13
Show Gist options
  • Select an option

  • Save dshook/3f125d3d9fae7df728c4 to your computer and use it in GitHub Desktop.

Select an option

Save dshook/3f125d3d9fae7df728c4 to your computer and use it in GitHub Desktop.
WEBLINC.formValidation = (function () {
'use strict';
var setup = function () {
var CREDIT_CARD_NUMBER_WHITE_LIST = ['1', '2', '3'],
setDefaults = function () {
$.validator.setDefaults({
meta: 'validation',
ignoreTitle: true,
errorClass: 'error'
});
},
customize = function () {
$.validator.addMethod('extendedCreditCard', function (value, element) {
if (_.contains(CREDIT_CARD_NUMBER_WHITE_LIST, value)) {
return true;
} else {
return $.validator.methods.creditcard.call(this, value, element);
}
}, $.validator.messages.creditcard);
};
setDefaults();
customize();
},
init = function ($scope) {
$('form', $scope).each(function () {
$(this).validate();
});
};
WEBLINC.modules.onDomReady(setup, init);
WEBLINC.modules.onDomUpdate(init);
return {
init: init
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment