4
Answers

How do I prevent numbers to be enter in a textbox ?

Goh Khen Hui

Goh Khen Hui

16y
7.5k
1

Hi guys I'm just starting with C#. I gotta do this for my project and have a hard time doing it.

I've gotta prevent people from entering numbers in my textbox of the program so they don't spoil it but I can't find anything that could do it. Anyone has any idea how? Tell my please thank you!!!

Answers (4)
0
Techy Wizard
NA 58 0 16y

You can use the Masked Textbox control. Set the mask property to '?'.

Accepted
0
Ryan Alford
NA 2.3k 891.7k 16y
am I missing something?  did he state that this was a web page?
0
Niradhip Chakraborty
NA 6.5k 527k 16y

Call this javascript function on onkeypress of textbox.

 

function isNumberKey(evt){

     var charCode = (evt.which) ? evt.which : event.keyCode

     if (charCode > 31 && (charCode < 48 || charCode > 57)){

     alert("Please enter digits");

          return false;

      }

      else{   

          return true;

      }   

}


 

0
Sivangari Vytheswaran
NA 26 64.5k 16y

Hi

 

using Onkeypress event ,u can solve ur problem.

write the code in java script

1.First find the keyboard event code.

     var key=e.keycode;

2.convert to this code to char and compare this char with ur string(if u give integers in this string ,u allow integer only.otherwise if u give a to z,u  allow only char)

3.if condition satisfy, return true,otherwise return false.

4.above funtion called in textbox onkeypress event.

Next Recommended Forum