How to check EMBG (Unique Master Citizen Number) using regex

In this post, I will share my implementation of how to check if some number looks like EMBG or Unique Master Citizen Number. For those of you who are not aware what is EMBG (Unique Master Citizen Number), please check Unique Master Citizen Number . Long story short, it's a composition of 13 digits, where first 7 digits are representing date in format ddMMyyy, and for the rest of the digits please check the wiki link. The yyy are the last 3 digits of year. The last digit from the 13-digit composition is checksum number, and should be checked outside of regex checking. The following regex should be validating EMBG (Unique Master Citizen Number) for Macedonia, but can be modified to check Unique Master Citizen Number for the rest of exYu countries (except Croatia, which seems that has changed the format according to the wiki article). The regex is validating 20th and 21th century year. Also, it's aware of leap year, and validating 2902 in ddMM input, if applicable.
Here is the regex :

^(?:(?:(?:0[1-9]|1\d|2[0-8])(?:0[1-9]|1[0-2])|(?:29|30)(?:0[13-9]|1[0-2])|31(?:0[13578]|1[02]))[09]\d{2}|2902[09](?:[02468][048]|[13579][26]))4[1-9]\d{4}$

 

And the diagram for the syntax is following:


Here are some tests using powershell:


The usage of this regex can be various, starting from beginner code input testing, to some exchange transport rule or data loss prevention rules. 

Feel free to test, and have some fun.



How to check EMBG (Unique Master Citizen Number) using regex

In this post, I will share my implementation of how to check if some number looks like EMBG or Unique Master Citizen Number. For those of yo...