|
1 | | -function formatExpirationDate (val) { |
| 1 | +function formatExpirationDate(val) { |
2 | 2 | var p1 = parseInt(val[0], 10), |
3 | 3 | p2 = parseInt(val[1], 10); |
4 | 4 |
|
5 | 5 | return /^\d$/.test(val) && "0" !== val && "1" !== val |
6 | 6 | ? "0" + val + " / " |
7 | 7 | : /^\d\d$/.test(val) |
8 | | - ? p2 > 2 && 0 !== p1 ? "0" + p1 + " / " + p2 : "" + val + " / " |
9 | | - : val |
| 8 | + ? p2 > 2 && 0 !== p1 |
| 9 | + ? "0" + p1 + " / " + p2 |
| 10 | + : "" + val + " / " |
| 11 | + : val; |
10 | 12 | } |
11 | 13 |
|
12 | 14 | function handleExpirationDate(element, focusOnFilled) { |
13 | | - ['input', 'keydown', 'keyup', 'mousedown', 'mouseup', 'select', 'contextmenu', 'drop'].forEach(function (key) { |
14 | | - element.addEventListener(key, function (e) { |
15 | | - if (/^\d+$/.test(e.key)) { |
16 | | - this.value = formatExpirationDate(this.value); |
17 | | - } |
| 15 | + ["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach( |
| 16 | + function (key) { |
| 17 | + element.addEventListener(key, function (e) { |
| 18 | + if (/^\d+$/.test(e.key)) { |
| 19 | + this.value = formatExpirationDate(this.value); |
| 20 | + } |
18 | 21 |
|
19 | | - if (/^\d{0,2}[\/]?\d{0,2}/.test(this.value)) { |
20 | | - this.oldValue = this.value; |
21 | | - this.oldSelectionStart = this.selectionStart; |
22 | | - this.oldSelectionEnd = this.selectionEnd; |
23 | | - } else if (this.hasOwnProperty('oldValue')) { |
24 | | - this.value = this.oldValue; |
25 | | - this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd); |
26 | | - } else { |
27 | | - this.value = ''; |
28 | | - } |
29 | | - if (this.oldSelectionEnd === 7 && key === 'keyup' && e.key.match(/^[0-9]$/)) { |
30 | | - secureFields.focus(focusOnFilled); |
31 | | - } |
32 | | - }); |
33 | | - }); |
| 22 | + if (/^\d{0,2}[\/]?\d{0,2}/.test(this.value)) { |
| 23 | + this.oldValue = this.value; |
| 24 | + this.oldSelectionStart = this.selectionStart; |
| 25 | + this.oldSelectionEnd = this.selectionEnd; |
| 26 | + } else if (this.hasOwnProperty("oldValue")) { |
| 27 | + this.value = this.oldValue; |
| 28 | + this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd); |
| 29 | + } else { |
| 30 | + this.value = ""; |
| 31 | + } |
| 32 | + if (this.oldSelectionEnd === 7 && key === "keyup" && e?.key?.match(/^[0-9]$/)) { |
| 33 | + secureFields.focus(focusOnFilled); |
| 34 | + } |
| 35 | + }); |
| 36 | + } |
| 37 | + ); |
34 | 38 | } |
35 | 39 |
|
36 | | -function getExpirationDateObject (value) { |
37 | | - var split = value.split('/') |
| 40 | +function getExpirationDateObject(value) { |
| 41 | + var split = value.split("/"); |
38 | 42 | expm = split[0].trim(); |
39 | 43 | expy = split[1].trim(); |
40 | 44 |
|
41 | 45 | return { |
42 | 46 | expm: expm, |
43 | | - expy: expy |
| 47 | + expy: expy, |
44 | 48 | }; |
45 | 49 | } |
0 commit comments