splitforms.com

Free tool / runs in your browser

Date regex tester: dd/mm/yyyy, mm/dd/yyyy and ISO

Choose a date format, test one value per line and copy the JavaScript regex or HTML pattern. Compare format checks with strict ranges and a leap-year aware ISO pattern before validating real calendar dates on your server.

^(?:(?!0000)[0-9]{4}-(?:(?:01|03|05|07|08|10|12)-(?:0[1-9]|[12][0-9]|3[01])|(?:04|06|09|11)-(?:0[1-9]|[12][0-9]|30)|02-(?:0[1-9]|1[0-9]|2[0-8]))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$

Encodes Gregorian month lengths and the divisible-by-4, century and divisible-by-400 leap rules for years 0001-9999. Unlike the simpler format patterns, this rejects invalid February 29 dates. Still validate on the server with the easier-to-maintain isRealDate(y,m,d) round-trip helper below.

2 of 5 pass

  • Pass2024-02-29
  • Fail2023-02-29
  • Pass2000-02-29
  • Fail1900-02-29
  • Fail2026-04-31

Use the HTML pattern on type="text", with required for empty values. Browsers anchor it to the whole value. pattern does not apply to type="date".

All 8 date regex patterns

All formats require leading zeros. Range and calendar patterns use years 0001-9999. Passing a format-only pattern does not guarantee a real date.

FormatRegexPass / fail examplesNotes
ISO yyyy-mm-dd (format only)^[0-9]{4}-[0-9]{2}-[0-9]{2}$Pass: 2026-12-31, 2026-13-32
Fail: 31/12/2026, 2026-1-01
The shape input type=date sends to the backend, for four-digit years. Only checks digit counts and separators, so 2026-13-32 passes. A format regex can't fully check February 29 or month lengths; a JS Date round-trip check is needed. See isRealDate(y,m,d) below.
dd/mm/yyyy^(?:0[1-9]|[12][0-9]|3[01])/(?:0[1-9]|1[0-2])/(?!0000)[0-9]{4}$Pass: 31/12/2026, 29/02/2024
Fail: 12/31/2026, 32/12/2026
Day first; requires leading zeros and bounds day to 01-31 and month to 01-12. A format regex can't fully check February 29 or month lengths; a JS Date round-trip check is needed. See isRealDate(y,m,d) below.
mm/dd/yyyy^(?:0[1-9]|1[0-2])/(?:0[1-9]|[12][0-9]|3[01])/(?!0000)[0-9]{4}$Pass: 12/31/2026, 02/29/2024
Fail: 31/12/2026, 13/01/2026
Month first; requires leading zeros and bounds month to 01-12 and day to 01-31. A format regex can't fully check February 29 or month lengths; a JS Date round-trip check is needed. See isRealDate(y,m,d) below.
dd-mm-yyyy^(?:0[1-9]|[12][0-9]|3[01])-(?:0[1-9]|1[0-2])-(?!0000)[0-9]{4}$Pass: 31-12-2026
Fail: 12-31-2026, 31/12/2026
Day first with hyphens and basic range checks. A format regex can't fully check February 29 or month lengths; a JS Date round-trip check is needed. See isRealDate(y,m,d) below.
dd.mm.yyyy^(?:0[1-9]|[12][0-9]|3[01])\.(?:0[1-9]|1[0-2])\.(?!0000)[0-9]{4}$Pass: 31.12.2026
Fail: 31x12x2026, 12.31.2026
Dots are escaped to match literal dots. A format regex can't fully check February 29 or month lengths; a JS Date round-trip check is needed. See isRealDate(y,m,d) below.
yyyy/mm/dd^(?!0000)[0-9]{4}/(?:0[1-9]|1[0-2])/(?:0[1-9]|[12][0-9]|3[01])$Pass: 2026/12/31
Fail: 2026/31/12, 2026-12-31
Year first with slashes and basic range checks. A format regex can't fully check February 29 or month lengths; a JS Date round-trip check is needed. See isRealDate(y,m,d) below.
ISO strict ranges^(?!0000)[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])$Pass: 2026-12-31, 2023-02-29
Fail: 2026-13-01, 2026-12-32, 0000-01-01
Rejects month 13 and day 32, but still accepts 2023-02-29. Years 0001-9999. A format regex can't fully check February 29 or month lengths; a JS Date round-trip check is needed. See isRealDate(y,m,d) below.
ISO leap-year aware^(?:(?!0000)[0-9]{4}-(?:(?:01|03|05|07|08|10|12)-(?:0[1-9]|[12][0-9]|3[01])|(?:04|06|09|11)-(?:0[1-9]|[12][0-9]|30)|02-(?:0[1-9]|1[0-9]|2[0-8]))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$Pass: 2024-02-29, 2000-02-29, 2026-12-31
Fail: 2023-02-29, 1900-02-29, 2100-02-29, 2026-04-31, 0000-01-01
Encodes Gregorian month lengths and the divisible-by-4, century and divisible-by-400 leap rules for years 0001-9999. Unlike the simpler format patterns, this rejects invalid February 29 dates. Still validate on the server with the easier-to-maintain isRealDate(y,m,d) round-trip helper below.

Regex vs <input type="date">

A populated native date input always submits YYYY-MM-DD whatever the user's locale, even when the picker displays day first or month first. Our input type=date format guide explains why the display follows the locale and how to show a fixed dd/mm/yyyy format. These ISO patterns cover four-digit years; HTML also permits longer positive years. Use min and max for date bounds and required to prevent empty values.

date.html

<label for="date">Date</label>
<input id="date" name="date" type="date" min="2026-01-01" max="2026-12-31" required>

The pattern attribute applies to text fields, not date inputs. Use a text input only when you need an explicit format such as dd/mm/yyyy, with a clear label and format hint. Regex checks text; the native date control also checks calendar validity.

See the HTML Standard date input specification for native date behavior.

Validate the date on the server too

A format regex can't fully check February 29. Even the strict range pattern accepts 2023-02-29 and April 31. A JS Date round-trip check is needed after matching the expected format: JavaScript normalizes impossible dates, so compare the resulting year, month and day to the originals.

validate-date.js

function isRealDate(y, m, d) {
  if (![y, m, d].every(Number.isInteger) || y < 1 || y > 9999) return false;
  const date = new Date(0);
  date.setUTCFullYear(y, m - 1, d);
  return date.getUTCFullYear() === y &&
    date.getUTCMonth() === m - 1 && date.getUTCDate() === d;
}

// Match the expected format before converting the components.
const match = /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/.exec(value);
const valid = match !== null && isRealDate(...match.slice(1).map(Number));

The leap-year aware ISO regex encodes Gregorian calendar rules, including centuries divisible by 400. The helper expresses calendar validation more clearly. UTC components avoid daylight-saving changes, and setUTCFullYear preserves years below 100. For slash formats, extract the components in the order you selected; do not rely on new Date(value) to guess a locale. Reject invalid values before storing them, then check permitted ranges and business rules on the server.

Date regex FAQ

What regex matches dd/mm/yyyy?

Use ^(?:0[1-9]|[12][0-9]|3[01])/(?:0[1-9]|1[0-2])/(?!0000)[0-9]{4}$. It accepts 31/12/2026 and rejects 12/31/2026, but still needs a calendar check for month lengths and February 29.

What regex matches mm/dd/yyyy?

Put the month first: ^(?:0[1-9]|1[0-2])/(?:0[1-9]|[12][0-9]|3[01])/(?!0000)[0-9]{4}$. It accepts 12/31/2026. Always choose the expected format explicitly: 03/04/2026 is ambiguous.

Can a date regex validate leap years?

A simple format or range regex cannot. The leap-year aware ISO pattern here encodes the full Gregorian rules: 2024-02-29 and 2000-02-29 pass; 2023-02-29 and 1900-02-29 fail. A Date round-trip check is easier to maintain on the server.

What format does input type=date submit?

A non-empty date value submits as YYYY-MM-DD regardless of the user's locale. The displayed date may look different. The HTML pattern attribute does not apply to type=date; use min and max for date bounds.

Should I validate dates on the server too?

Yes. Browser validation can be bypassed. Check the expected string format, parse year, month and day explicitly, and round-trip the components through a Date. Then enforce your allowed date range and business rules.

Date and time fields

Need a time as well? See input type=datetime-local for local date and time values without a time zone.