Last active
February 21, 2017 18:28
-
-
Save gosseti/8716378 to your computer and use it in GitHub Desktop.
A credit card form using jQuery.payment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- this should be inside as part of your <form> element --> | |
<div class="form-row cardInfo__cc-exp"> | |
<label for="cc-exp"> | |
<abbr title="required">*</abbr> | |
<span>Expires</span> | |
</label> | |
<!-- we set type="tel" because HTML5 validations don’t play well with type="number" --> | |
<input id="cc-exp" type="tel" data-stripe="expiry" class="cc-exp" placeholder="MM / YY" autocompletetype="cc-exp" required="required"> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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').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').addClass('identified'); | |
} else { | |
// remove is again if the expiry becomes invalid | |
$('.cc-exp').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(); | |
}); | |
}); |
loved it 😘
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
Awesome