validation to enter alpha numeric values in windows applications(C#)

Posted by Mahesh_Chs under C# on 10/2/2012 | Points: 10 | Views : 4714 | Status : [Member] | Replies : 6
hi,

I want to validate a textbox for driving licence(it allows alphanumerics values),
but even if i give complete numbers or alphabets the form is submitting but i want to submit the form if i give alphanumeric values only




Responses

Posted by: Divyaselvarathinam on: 10/3/2012 [Member] Starter | Points: 25

Up
0
Down
You can use textbox key press event
check the link
http://www.dotnetspider.com/resources/23851-Textbox-validation-Allows-Only-Alpha-Numeric-s.aspx

Divya

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mahesh_Chs on: 10/3/2012 [Member] Starter | Points: 25

Up
0
Down
hii,

thanks for reply

i have already written the code like this, but if we give all numerics the form is submitting, or if we give all alphabets the form is submitting, my requirement is if i give both alphabets and numerics then only the form should submit

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 10/3/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Try this code in your Input Box

  private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

{
if (!(Char.IsLetter(e.KeyChar) || Char.IsDigit(e.KeyChar) || Char.IsControl(e.KeyChar)))
{
e.Handled = true;
}
}



Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mahesh_Chs on: 10/4/2012 [Member] Starter | Points: 25

Up
0
Down
hii Naraayanan


In my code the textbox is accepting both numerics and alphabets, but until i enter both numerics and alphabets the form should not be submit.



Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Naraayanan on: 10/4/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
Could you explain your Problem?


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mahesh_Chs on: 10/4/2012 [Member] Starter | Points: 25

Up
0
Down
hii,

yes i am able to enter charecters and digits, if i enter both charecters and digits then only the form should submit otherwise it shouldn't. suppose if i enter complete charecters or if i enter complete digits the form should not submit.....if i enter both only the form should submit

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response