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.



3 comments:

  1. I love your content and the lessons you share with your readers. Every time I read a post how to write a dissertation methodology I feel like I am able to take advantage of this post.

    ReplyDelete
  2. Superslot or Thai home language is called super slot. We are an online slots provider, there are many slots games to choose from, play a lot on mobile phones, number 1, both free credit 50, 100, 150, 200 that can support both IOS and Android systems, easy to apply, have easy access to log. -in has a system to make a top-up transaction Withdraw money via automatic system 24 hours a day,

    ReplyDelete
  3. You've made some good points there. I looked on the internet for additional information about the issue and found most people will go along with your views on this website. สล็อต ฟรีเครดิต

    ReplyDelete

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...