The first six digits represent your registered residence, the seventh to fourteenth digits represent your birth date, and the fifteenth to seventeenth digits represent your gender (even numbers are females, odd numbers are males). According to this information, I obtained my birthday and gender based on the ID number after entering the employee's ID card developed by the system.
The code written in C# is as follows:
/// <summary> /// Define the legality of the ID number in the Validated event of the textBox_IdentityCard and get the birthday and gender based on the ID number/// </summary> private void textBox_IdentityCard_Validated(object sender, EventArgs e) { try { //Get the entered ID number string identityCard = textBox_IdentityCard.(); if ((identityCard)) { //The ID number cannot be empty, if it is empty, return ("The ID number cannot be empty!"); if (textBox_IdentityCard.CanFocus) { textBox_IdentityCard.Focus();//Set the current input focus to textBox_IdentityCard } return; } else { //Identity card number can only be 15 or 18 digits, otherwise it is illegal if ( != 15 && != 18) { ("The ID number is 15 or 18 digits, please check!"); if (textBox_IdentityCard.CanFocus) { textBox_IdentityCard.Focus(); } return; } } string birthday = ""; string sex = ""; // Process 18-digit ID number to get birthday and gender codes from the number if ( == 18) { birthday = (6, 4) + "-" + (10, 2) + "-" + (12, 2); sex = (14, 3); }<br> // Process 15-digit ID number to get birthday and gender codes from the number if ( == 15) { birthday = "19" + (6, 2) + "-" + (8, 2) + "-" + (10, 2); sex = (12, 3); }<br> textBox_Birthday.Text = birthday; //Gender code is even, female, odd number is male if ((sex) % 2 == 0) { this.comboBox_Sex.Text = "female"; } else { this.comboBox_Sex.Text = "male"; } } catch (Exception ex) { ("Issue number entered incorrectly"); if (textBox_IdentityCard.CanFocus) { textBox_IdentityCard.Focus(); } return; } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.