EasyRegex Logo
EasyRegex
Nuevo

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

Javascript

Expresión Regular

^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/(?:\d{2})?\d{2}$
Copiar
¿Tienes Comentarios?

Explicación

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

Ejemplo de Uso

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');
}
Copiar
Prueba la expresión

Expresiones Regulares Similares