basics · 2025-02-10 · 5 min read

Expiry dates: valid through the last day of the month

A card marked 05/30 works until 23:59 on 31 May 2030. Small detail, common bug — and one of several traps in a field that looks trivial.

Valid through the last day of the printed month.
Valid through the last day of the printed month. — © Matheus Bertelli · Pexels

The expiry printed on a card is a month and a two-digit year. The card remains valid through the final day of that month, so validation must compare against the end of the month, not its start. Our inspection bench applies exactly this rule — try 01/26 versus the current month to see the difference.

The end-of-month rule in code

Build a date for the first day of the following month and check that now is earlier than it. Equivalent: new Date(year, month, 0, 23, 59, 59) in JavaScript gives the last second of the expiry month because day 0 of the next month rolls back.

Edge cases worth a unit test

  • Two-digit years: 30 means 2030. Decide explicitly what 99 means; most libraries assume the current century.
  • Month 00 or 13: reject with a clear message, not a generic 'invalid'.
  • Time zones: the issuer evaluates expiry in its own zone; a card may be accepted a few hours after your local midnight.
  • Dates more than ~20 years out are almost always typos — warn, don't block.
  • Expiring this month is valid but worth a soft notice for subscriptions.

Formatting and autofill

Accept 4 digits and insert the slash automatically, keep the caret stable, and set autocomplete="cc-exp" (or cc-exp-month / cc-exp-year) so browsers and password managers can fill the field — the MDN autocomplete reference lists the tokens. More on input ergonomics in formatting as you type.

An unexpired date proves nothing about the account. Like Luhn, it is a typo filter; the issuer's authorization is the real check.
Compare against month-end, not month-start.
Compare against month-end, not month-start.

Keywords: card expiry date, expiration date validation, MM/YY, end of month, cc-exp autocomplete, expired card

Frequently asked questions

Is a card valid on the last day of its expiry month?

Yes. A card marked 05/30 is valid through 31 May 2030 and expires at the start of June.

What autocomplete value should an expiry field use?

cc-exp for a combined MM/YY field, or cc-exp-month and cc-exp-year for separate fields.

On this site

External references

Related articles

تاريخ الانتهاء: صالح حتى آخر يوم في الشهر — النسخة العربية

بطاقة مكتوب عليها 05/30 تعمل حتى 23:59 من 31 مايو 2030. تفصيل صغير وخطأ شائع — وواحد من عدة فخاخ في حقل يبدو تافهًا.

التاريخ المطبوع على البطاقة شهرٌ وسنة من خانتين. تبقى البطاقة صالحة حتى اليوم الأخير من ذلك الشهر، لذا يجب أن تقارن عملية التحقق بنهاية الشهر لا ببدايته. منضدة الفحص لدينا تطبّق هذه القاعدة بالضبط — جرّب 01/26 مقابل الشهر الحالي لترى الفرق.

قاعدة نهاية الشهر في الكود

ابنِ تاريخًا لأول يوم من الشهر التالي وتحقق أن الآن أسبق منه. أو ما يعادله: ‏new Date(year, month, 0, 23, 59, 59) في JavaScript يعطي آخر ثانية من شهر الانتهاء لأن اليوم 0 من الشهر التالي يرتدّ إلى الخلف.

حالات طرفية تستحق اختبار وحدة

  • السنوات بخانتين: 30 تعني 2030. حدّد صراحة ماذا تعني 99؛ معظم المكتبات تفترض القرن الحالي.
  • الشهر 00 أو 13: ارفض برسالة واضحة لا بعبارة «غير صالح» عامة.
  • المناطق الزمنية: يقيّم المُصدِر الانتهاء في منطقته؛ وقد تُقبل بطاقة بعد منتصف ليلك المحلي ببضع ساعات.
  • التواريخ الأبعد من 20 سنة تقريبًا تكون أخطاء كتابية غالبًا — نبّه ولا تمنع.
  • الانتهاء هذا الشهر صالح لكنه يستحق تنبيهًا لطيفًا في الاشتراكات.

التنسيق والتعبئة التلقائية

اقبل 4 خانات وأدرج الشرطة المائلة تلقائيًا، وحافظ على ثبات المؤشر، واضبط autocomplete="cc-exp" (أو cc-exp-month / cc-exp-year) ليستطيع المتصفح ومديرو كلمات المرور ملء الحقل — مرجع MDN للإكمال التلقائي يسرد القيم. المزيد عن تجربة الإدخال في التنسيق أثناء الكتابة.

التاريخ غير المنتهي لا يثبت شيئًا عن الحساب. مثل لون، هو مرشّح للأخطاء الكتابية؛ وتفويض المُصدِر هو الفحص الحقيقي.

أسئلة شائعة

هل البطاقة صالحة في آخر يوم من شهر انتهائها؟

نعم. البطاقة المكتوب عليها 05/30 صالحة حتى 31 مايو 2030 وتنتهي مع بداية يونيو.

أي قيمة autocomplete يستخدم حقل الانتهاء؟

cc-exp لحقل MM/YY مدمج، أو cc-exp-month وcc-exp-year للحقول المنفصلة.

Educational content — not legal or financial advice. Open the interactive Check Digit Lab →