Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8910901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:48:42+00:00 2026-06-15T03:48:42+00:00

I have problem with writing regular expression ( php / js ) for Latvian

  • 0

I have problem with writing regular expression ( php / js ) for Latvian citizen personal codes.
Every citizen in Latvia has own personal code. The format is 11 digits and after the sixth digit there is dash. So first 6 digits are date of birth.

ddmmyy ( at example: 130589 ) then goes dash ( – ) then goes seventh digit, that can be 0, 1 or 2 which means century ( 0 for 19. century and 2 for 21. century ), and then goes digits from 0000 to 9999

Examples:

080189-12602

08   - day
01   - month
89   - year
-    - dash
1    - 20th century
2602 - random 4 digit combination.

So question is can someone help me with writing regular expression ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:48:44+00:00Added an answer on June 15, 2026 at 3:48 am

    I recommend that you do not validate the date with the regex. Instead check only for the correct format:

    /^(\d{6})-[012]\d{4}$/
    

    That matches 6 arbitrary digits, a dash, then a digit from 0 to 2, then 4 more arbitrary digits. Afterwards you will find the date part in capturing group number 1, which you can check for a valid date. Alternatively you could extract days, months, years separately:

    /^(\d{2})(\d{2})(\d{2})-[012]\d{4}$/
    

    Now the days are in capture 1, the months in capture 2, the years in capture 3. The validation of the date ranges could in theory be done with the regex but it really not recommended (the regex becomes really bloated and unmaintainable). That is why you should just check that there are digits, and then you can use your programming language (PHP or JS) to check that the given numbers form a valid date.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with Regular Expressions. I'm writing a small program that matches
I have come across an annoying problem while writing some PHP4 code. I renamed
I'm having a problem writing a regular expression for matching HTML tags. I found
I have one interesting problem. I must parse mail body (regular expression), get some
I've been writing PHP code for years. And now I have plenty of reusable
I have a problem with writing a catch clause for an exception that is
I'm writing chat client/server app with c# and I have problem with threading. I
I have problem concerning python packages and testing. I'm writing an application using wx
I'm writing an app in Visual Studio C++ and I have problem with assigning
I have a problem with regards to writing the correct regex for the examination

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.