(value)
| 376 | } |
| 377 | |
| 378 | function parseExpiryInput(value) { |
| 379 | const raw = String(value || "").trim(); |
| 380 | if (!raw) { |
| 381 | return { exp_month: "", exp_year: "" }; |
| 382 | } |
| 383 | |
| 384 | const slashMatch = raw.match(/^(\d{1,2})\s*\/\s*(\d{1,4})$/); |
| 385 | if (slashMatch) { |
| 386 | return { |
| 387 | exp_month: normalizeMonth(slashMatch[1]), |
| 388 | exp_year: normalizeYear(slashMatch[2]), |
| 389 | }; |
| 390 | } |
| 391 | |
| 392 | const digits = raw.replace(/\D/g, ""); |
| 393 | if (!digits) { |
| 394 | return { exp_month: "", exp_year: "" }; |
| 395 | } |
| 396 | if (digits.length <= 2) { |
| 397 | return { exp_month: normalizeMonth(digits), exp_year: "" }; |
| 398 | } |
| 399 | return { |
| 400 | exp_month: normalizeMonth(digits.slice(0, 2)), |
| 401 | exp_year: normalizeYear(digits.slice(2)), |
| 402 | }; |
| 403 | } |
| 404 | |
| 405 | function normalizeExpiryInputForTyping(value) { |
| 406 | const digits = String(value || "").replace(/\D/g, "").slice(0, 6); |
no test coverage detected