Skip to content

Instantly share code, notes, and snippets.

@gosseti
Last active February 21, 2017 18:28
Show Gist options
  • Save gosseti/8716378 to your computer and use it in GitHub Desktop.
Save gosseti/8716378 to your computer and use it in GitHub Desktop.
A credit card form using jQuery.payment
// include jquery and jquery.payment before here
$(function() {
var validateExpiry = function() {
// set variables for the expiry date validation and expiry 'splitter' object
var expiry = $('.cc-exp__live').payment('cardExpiryVal');
var validateExpiry = $.payment.validateCardExpiry(expiry["month"], expiry["year"]);
// perform an if statement on whether the card’s expiry is valid or not
if (validateExpiry) {
// if the expiry is valid add the identified class
$('.cc-exp__live').addClass('identified');
} else {
// remove is again if the expiry becomes invalid
$('.cc-exp__live').removeClass('identified');
}
}
// this runs the above function every time stuff is entered into this expiry input
$('.cc-exp__live').bind('change paste keyup', function() {
validateExpiry();
});
});
@kamaroly
Copy link

kamaroly commented May 4, 2015

Awesome

@Waterloo
Copy link

loved it 😘

@asthago
Copy link

asthago commented Nov 27, 2015

Placed styles.css in <style> and validations.js in <script> but its not working for me :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment