Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
regular expression to test date format 'dd-mm-yyyy'
Examples
let date = '31-12-2004'
date_regex = /^(0[1-9]|[1-2][0-9]|3[0-1])-(0[1-9]|1[0-2])-[0-9]{4}$/;
date_regex.test( date )
let date = 31
let date_regex = /^(0[1-9]|[1-2][0-9]|3[0-1])$/;
date_regex.test( date )
let date = 12
let date_regex = /^(0[1-9]|1[0-2])$/;
date_regex.test( date )
let date = 2004
let date_regex = /^[0-9]{4}$/;
date_regex.test( date )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment