REGEXVAULTv2.0
Finance/Financial Formats
Verified Safe

Accounting Period (YYYY-MM) Regex for JavaScript

/^((?:19|20)[0-9]{2})-(0[1-9]|1[0-2])$/

What this pattern does

This page provides a well-structured, multi-part regular expression for matching accounting period (yyyy-mm), ported and verified for JavaScript. Financial data validation has zero tolerance for false negatives — a missed invalid entry can corrupt downstream calculations. The snippet below is ready to drop into your JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.

Javascript Implementation

Javascript
// Accounting Period (YYYY-MM)
// ReDoS-safe | RegexVault — Finance > Financial Formats

const accountingPeriodYyyymmRegex = /^((?:19|20)[0-9]{2})-(0[1-9]|1[0-2])$/;

function validateAccountingPeriodYyyymm(input: string): boolean {
  return accountingPeriodYyyymmRegex.test(input);
}

// Example
console.log(validateAccountingPeriodYyyymm("2024-01")); // true

Test Cases

Matches (Valid)
Rejects (Invalid)
2024-012024-00
2024-122024-13
1999-0624-01
2025-032024/01
2024-1
2024-012

When to use this pattern

This pattern is drawn from the Finance > Financial Formats category and carries a ReDoS-safe certification. That matters for JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

Fiscal year start varies by company and jurisdiction: US government FY starts October, Singapore FY starts April for many companies. Store fiscal year alongside calendar period.

Technical Notes

Capture group 1: year (1900-2099), group 2: month (01-12). Accounting periods usually follow calendar months but some companies use fiscal months not aligned to calendar months.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern