I have validated a text box that only PAN NO should be enter in that text box
It should be of 10 character first 5 digit will be Alphabet next 4 digit will be number and next one is alphabet
here txtPAN(TextBox) length should be fixed 10 chracter
ex : BJJPA4563A
private void txtPAN_KeyPress(object sender, KeyPressEventArgs e)
{
ValidatePANNO(e);
}
void ValidatePANNO(KeyPressEventArgs e)
{
if (!char.IsLetterOrDigit(e.KeyChar) && e.KeyChar != 8)
{
e.Handled = true;
return;
}
if (e.KeyChar == 8)
{
return;
}
int len = txtPAN.TextLength;
if (len < 5)
{
if (char.IsLetter(e.KeyChar))
{
}
else
{
e.Handled = true;
}
}
else
{
if (len == 9)
{
if (char.IsLetter(e.KeyChar))
{
return;
}
}
if (char.IsLetter(e.KeyChar))
{
e.Handled = true;
}
else
{
if (len == 9)
{
if (!char.IsLetter(e.KeyChar))
{
e.Handled = true;
}
}
}
}
}
Good Work..
ReplyDelete