forked from stripe-archive/jquery.payment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
75 lines (56 loc) · 2.11 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="../lib/jquery.payment.js"></script>
<style type="text/css" media="screen">
input.invalid {
border: 2px solid red;
}
.validation.failed:after {
color: red;
content: 'Validation failed';
}
.validation.passed:after {
color: green;
content: 'Validation passed';
}
</style>
<script>
jQuery(function($){
$('[data-numeric]').payment('restrictNumeric');
$('.cc-number').payment('formatCardNumber');
$('.cc-exp').payment('formatCardExpiry');
$('.cc-cvc').payment('formatCardCVC');
$('form').submit(function(e){
e.preventDefault();
$('input').removeClass('invalid');
$('.validation').removeClass('passed failed');
var cardType = $.payment.cardType($('.cc-number').val());
$('.cc-number').toggleClass('invalid', !$.payment.validateCardNumber($('.cc-number').val()));
$('.cc-exp').toggleClass('invalid', !$.payment.validateCardExpiry($('.cc-exp').payment('cardExpiryVal')));
$('.cc-cvc').toggleClass('invalid', !$.payment.validateCardCVC($('.cc-cvc').val(), cardType));
if ( $('input.invalid').length ) {
$('.validation').addClass('failed');
} else {
$('.validation').addClass('passed');
}
});
});
</script>
</head>
<body>
<form novalidate autocomplete="on">
<h2>Card number formatting</h2>
<input type="text" class="cc-number" pattern="\d*" x-autocompletetype="cc-number" placeholder="Card number" required>
<h2>Expiry formatting</h2>
<input type="text" class="cc-exp" pattern="\d*" x-autocompletetype="cc-exp" placeholder="Expires MM/YY" required maxlength="9">
<h2>CVC formatting</h2>
<input type="text" class="cc-cvc" pattern="\d*" x-autocompletetype="cc-csc" placeholder="Security code" required autocomplete="off">
<h2>Restrict Numeric</h2>
<input type="text" data-numeric>
<h2 class="validation"></h2>
<button type="submit">Submit</button>
</form>
</body>
</html>