diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-11-25 22:21:04 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-11-25 22:21:04 -0500 |
| commit | 98e21c4f1b096fc117a6a0f770bb69ab7c83914d (patch) | |
| tree | 00b5d074b011fc26084b37dd662e4fc95f75c492 /StoneIsland/www/js | |
| parent | ec87912a5ca1c0d6862b07012fdbbdf2d4b4f86a (diff) | |
validate cc number
Diffstat (limited to 'StoneIsland/www/js')
| -rw-r--r-- | StoneIsland/www/js/lib/nav/CreditCardView.js | 21 | ||||
| -rw-r--r-- | StoneIsland/www/js/vendor/jquery.creditCardValidator.js | 3 |
2 files changed, 22 insertions, 2 deletions
diff --git a/StoneIsland/www/js/lib/nav/CreditCardView.js b/StoneIsland/www/js/lib/nav/CreditCardView.js index eaab7086..8d805b80 100644 --- a/StoneIsland/www/js/lib/nav/CreditCardView.js +++ b/StoneIsland/www/js/lib/nav/CreditCardView.js @@ -3,13 +3,21 @@ var CreditCardView = View.extend({ template: $("#creditcard_template").html(), + cardOptions: { + accept: ['visa', 'mastercard', 'amex'], + }, + events: { }, initialize: function(opt){ this.parent = opt.parent this.setElement( this.parent.$(".cc") ) - this.parent.$(".cc").html(this.template) + this.$el.html(this.template) + + this.$number = this.$("[name=Number]") + console.log(this.$number) + this.$number.validateCreditCard(this.updateCard.bind(this), this.cardOptions) }, populate: function(data){ @@ -18,15 +26,26 @@ var CreditCardView = View.extend({ this.load_data(data) }, + updateCard: function(card){ + console.log(card) + // card.card_type.name + // card.card_type.valid + }, + validate_presence: { 'Number': 'Please enter your credit card number.', 'CVV': 'Please enter your security code.', }, validate_fields: function(data, errors){ + + var card = this.$number.validateCreditCard(this.cardOptions) + + if (! card.valid) { errors.push([ "Number", "Your card number is invalid." ]) if (! data.ExpirationMonth || data.ExpirationMonth == "NONE") { errors.push([ "ExpirationMonth", "Please enter the expiration month." ]) } if (! data.ExpirationYear || data.ExpirationYear == "NONE") { errors.push([ "ExpirationYear", "Please select the expiration month." ]) } data.UserId = auth.user_id + }, }) diff --git a/StoneIsland/www/js/vendor/jquery.creditCardValidator.js b/StoneIsland/www/js/vendor/jquery.creditCardValidator.js index a9117abe..3ec39f27 100644 --- a/StoneIsland/www/js/vendor/jquery.creditCardValidator.js +++ b/StoneIsland/www/js/vendor/jquery.creditCardValidator.js @@ -181,11 +181,12 @@ IN THE SOFTWARE. return function() { var number; number = normalize($(_this).val()); + console.log(number) return validate_number(number); }; })(this); normalize = function(number) { - return number.replace(/[ -]/g, ''); + return (number || "").replace(/[ -]/g, ''); }; if (!bind) { return validate(); |
