EasyRegex Logo
EasyRegex
Nouveau

Match Dates in DD/MM/YYYY or DD/MM/YY Format

Javascript

Expression Régulière

^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/(?:\d{2})?\d{2}$
Copier
Avez-vous des Retours ?

Explication

This regex pattern matches dates in the format DD/MM/YYYY or DD/MM/YY. It allows for days from 01 to 31, months from 01 to 12, and optionally matches the year in either two-digit (YY) or four-digit (YYYY) format.

Javascript

Exemple d'Utilisation

const regex = /^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/(?:\d{2})?\d{2}$/;
const date = '25/12/2021';
if(regex.test(date)) {
    console.log('Valid date format');
} else {
    console.log('Invalid date format');
}
Copier
Testez l'expression

Expressions Régulières Similaires