Created
January 9, 2013 20:11
-
-
Save sstarr/4496379 to your computer and use it in GitHub Desktop.
Randomly generate a valid Danish CPR number (personnummer) for someone born between 20 and 50 years ago.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on the format described in this Wikipedia article: http://en.wikipedia.org/wiki/Personal_identification_number_(Denmark) | |
"#{(20.years.ago - (0..11000).to_a.sample.days).strftime('%d%m%y')}-1#{'%03d' % (0..999).to_a.sample}" | |
# Regular expression to validate a CPR number | |
/\b(0[1-9]|[12]\d|3[01])(0[1-9]|1[0-2])\d{2}-\d{4}\b/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment