After the student's ID card is entered, the control focus is transferred and the birthday and gender are obtained based on the ID card number.

Source: Internet
Author: User
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 ;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.