Try it out on these example inputs:

back to RegexSwap.

Danish CPR number

Regular expression:

^(0[1-9]|[12]\d|3[01])((0[1-9])|(1[0-2]))[0-9]{2}(\Q-\E)?[0-9]{4}$

Categories:

Popularity:

You need to be logged in to cast votes on regexes.

Good
0
Bad
0

Author description and comments (2)

Topic by
kasper

2009-01-05
22:16

Description

Definately not the most advanced and accurate Danish CPR (social security) number validation regex, but it's pretty useful and easy to figure out.

Comment by
broberg


I'm afraid this will fail on some inputs, The dates of 10,20 of the month will fail.
I would switch out the "^(((0|1|2)[1-9])|(3[0-1]))" part with "^(0[1-9]|[12]\d|3[01])"

Comment by
kasper


Hi broberg,

Thanks for noting this issue with the regex! I've updated it with your fine suggestion! :-)

You need to be logged in to participate

In order to post your own comments on this regex, you need to be logged in.

Username:

Log in by clicking the login link at the top of the screen