I have been in touch with the registration system and the authentication system to know the information in the ID card number. For 18-digit ID cards, the first six represent the location of your household registration, the seventh to 14th digits represent the year of birth, and the fifth to 15th digits represent your gender (even numbers are female and odd numbers are male). According to this information, after I enter the student's ID card in the system, the control focus will be transferred Based on the ID card number to get the birthday and gender, written in C # Code As follows:
/// <Summary>
///Define the validity of the ID card number in the control Verification textbox_identitycard validated event and get the birthday and gender according to the ID card number.
/// </Summary>
Private VoidTextbox_identitycard_validated (ObjectSender, eventargs E)
{
Try
{
String Identitycard = Textbox_identitycard.text.trim (); // Obtain the entered ID number
If ( String . Isnullorempty (identitycard ))
{
MessageBox. Show ( " ID card number cannot be blank! " ); // ID card number cannot be blank. If it is blank, return
If (Textbox_identitycard.canfocus)
{
Textbox_identitycard.focus (); // Set the current input focus to textbox_identitycar
}
Return ;
}
Else
{
If (Identitycard. Length ! = 15 && Identitycard. Length ! = 18 ) // The ID card number can only be 15 or 18 other illegal characters
{
MessageBox. Show ("The ID number is 15 or 18 characters. Check the number!");
If (Textbox_identitycard.canfocus)
{
Textbox_identitycard.focus ();
}
Return ;
}
}
String Birthday = "" ;
String Sex = "" ;
If (Identitycard. Length = 18 ) // Handle the 18-digit ID card number to get the birthday and gender code from the number
{
Birthday = Identitycard. substring ( 6 , 4 ) + " - " + Identitycard. substring ( 10 , 2 ) + " - " + Identitycard. substring ( 12 , 2 );
Sex = Identitycard. substring ( 14 , 3 );
}
If (Identitycard. Length = 15 )
{
Birthday = " 19 " + Identitycard. substring ( 6 , 2 ) + " - " + Identitycard. substring ( 8 , 2 ) + " - " + Identitycard. substring ( 10 , 2 );
Sex = Identitycard. substring ( 12 , 3 );
}
Textbox_birthday.text = Birthday;
If ( Int . Parse (sex) % 2 = 0 ) // If the gender code is an even number, the female odd number is male.
{
This . Combobox_sex.text = " Female " ;
}
Else
{
This . Combobox_sex.text = " Male " ;
}
}
Catch (Exception ex)
{
MessageBox. Show ( " Incorrect ID card number " );
If (Textbox_identitycard.canfocus)
{
Textbox_identitycard.focus ();
}
Return ;
}
}