18-bit ID card, the front six representatives of your domicile, seventh to 14th to represent your date of birth, 15th to 17th to represent your gender (even number of female, odd male), according to this information, I am in the system development of the input employee ID card after the control focus shift according to the ID number to get birthdays and sex.
The code written in C # is as follows:
<summary>///defines the legality of the identity card number in the validated event of the control validation Textbox_identitycard and obtains birthdays and gender///</summary> privat according to the ID number e void textbox_identitycard_validated (object sender, EventArgs e) {try {//Get input ID number string Identitycard =
TextBox_IdentityCard.Text.Trim (); if (string. IsNullOrEmpty (Identitycard)) {//ID number cannot be null, if empty return MessageBox.Show ("ID number cannot be empty!")
");
if (textbox_identitycard.canfocus) {textbox_identitycard.focus ();//Set current input focus to Textbox_identitycard}
Return else {//ID number can only be 15-bit or 18-bit other illegal if (identitycard.length!= && identitycard.length!= 18 {MessageBox.Show ("ID number is 15 digits or 18 digits, please check!")
");
if (textbox_identitycard.canfocus) {textbox_identitycard.focus ();
} return;
} String birthday = "";
string sex = ""; Processing 18-bit ID number from the number to get birthday and sex code if (identitycard.length = =) {Birthday =Identitycard.substring (6, 4) + "-" + identitycard.substring (2) + "-" + identitycard.substring (12, 2);
Sex = identitycard.substring (14, 3); }<br>//Processing 15-bit ID number from the number to get birthday and sex code if (identitycard.length = =) {birthday = "" "+ Identitycard.
Substring (6, 2) + "-" + identitycard.substring (8, 2) + "-" + identitycard.substring (10, 2);
Sex = identitycard.substring (12, 3);
}<br> textbox_birthday.text = birthday; The sex code is even if the female is odd for a male if (int.
Parse (Sex)% 2 = 0) {This.comboBox_Sex.Text = "female";
else {this.comboBox_Sex.Text = "male";
The catch (Exception ex) {MessageBox.Show ("wrong ID number entered incorrectly");
if (textbox_identitycard.canfocus) {textbox_identitycard.focus ();
} return;
}
}
above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud-dwelling community.