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
Jignesh KumarPosted Oct 31, 2020, 6:02 AM
Amit MohantyPosted Oct 30, 2020, 6:50 AM
S JPosted Oct 29, 2020, 11:48 PM
Rajanikant HawaldarPosted Oct 29, 2020, 11:29 PM
S JPosted Oct 29, 2020, 2:44 AM
Sonu GuptaPosted Oct 29, 2020, 2:29 AM
S JPosted Oct 28, 2020, 11:54 PM
Jonathas SucupiraPosted Aug 16, 2011, 12:14 PM
Vilas GitePosted Aug 16, 2011, 10:00 AM
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"
Priya LingePosted Aug 16, 2011, 8:25 AM
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.