Hi,
I am trying to provide validation on textbox that it accept only digits. it executes properly by following c# code
on textbox keypress event,
if(!(char.IsDigit (e.KeyChar)))
{
e.Handled = true;
}
But back space button is also not working on this. I Want, Back Space button work on textbox.
Where is the Problem In my Code?
Thanks in Advance
Loading

Priya LingeRank #785 · 2.9K reputationPosted Aug 16, 2011, 4:25 AM EDT
Please try this,
if (e.KeyChar == (char)Keys.Back && !(char.IsControl(e.KeyChar)))
{
e.Handled = true;
}
Use !Char.IsControl(e.KeyChar) so that all the "control" characters like the backspace key and clipboard keyboard shortcuts are exempted.
IsControl :Indicates whether a specified Unicode character is categorized as a control character.
Hope this will help you.
Thanks.
Vilas GiteRank #951 · 2.1K reputationPosted Aug 16, 2011, 6:00 AM EDT
Hi Alok, Welcome here,
Refer:
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/3000c21c-c0ad-4c04-afca-6b16833804a6/
Thanks.
------------------------------------------------------------------------------
If this reply helps your post…then check "This is correct answer"
Jonathas Sucupira122 reputationPosted Aug 16, 2011, 8:14 AM EDT
S JRank #7,785 · 234 reputationPosted Oct 28, 2020, 7:54 PM EDT
Sonu GuptaRank #1,261 · 1.4K reputationPosted Oct 28, 2020, 10:29 PM EDT
S JRank #7,785 · 234 reputationPosted Oct 28, 2020, 10:44 PM EDT
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Oct 29, 2020, 7:29 PM EDT
S JRank #7,785 · 234 reputationPosted Oct 29, 2020, 7:48 PM EDT
Amit MohantyRank #112 · 20K reputationPosted Oct 30, 2020, 2:50 AM EDT
Jignesh KumarRank #91 · 22.9K reputationPosted Oct 31, 2020, 2:02 AM EDT