How to verify PAN card?

前端 未结 15 1430
予麋鹿
予麋鹿 2021-02-13 11:46

How to check the validation of edittext for pan card like \"ABCDE1234F\". I am confused how to check the the validation for this. Please help me guys. I will appreciate any kind

15条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-13 12:26

    You can use Key press Event for PAN Card Validation in C#

    enter code here
    

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

        {           
            int sLength = textBox1.SelectionStart;  
    
            switch (sLength)
            {
                case 0:
    
                case 1:
    
                case 2:
    
                case 3:
    
                case 4:
    
                        if (char.IsLetter(e.KeyChar) || Char.IsControl(e.KeyChar))
                        {
                            e.Handled = false;
                        }
                        else
                        {
                            e.Handled = true;
                        }
                        break;
    
                case 5:
    
                case 6:
    
                case 7:
    
                case 8:
                        if (char.IsNumber(e.KeyChar) || Char.IsControl(e.KeyChar))
                        {
                            e.Handled = false;
                        }
                        else
                        {
                            e.Handled = true;
                        }
                        break;
                case 9:
                        if (char.IsLetter(e.KeyChar) || Char.IsControl(e.KeyChar))
                        {
                            e.Handled = false;
                        }
                        else
                        {
                            if (Char.IsControl(e.KeyChar))
                            {
                                e.Handled = false;
                            }
    
                            else
                            {
                                e.Handled = true;
                            }
                        }
                        break;
                default:
                        if (Char.IsControl(e.KeyChar))
                        {
                            e.Handled = false;
                        }
    
                        else
                        {
                            e.Handled = true;
                        }
                        break;
            }
        }
    

提交回复
热议问题