C# - How to make a Textbox Accepts Only Numbers Or Only Characters In C# [with source code]

C# - How to make a Textbox Accepts Only Numbers Or Only Characters In C# [with source code]

1BestCsharp blog

7 лет назад

86,562 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

lilia sara
lilia sara - 26.01.2022 17:20

ادا في صوت كان احسن

Ответить
Hassan Nasar
Hassan Nasar - 12.01.2022 08:29

Thank you so much for that

Ответить
Dark DICE
Dark DICE - 02.06.2021 22:49

Easy and works perfectly

Ответить
Vivaldo Roque - SpeedCuber
Vivaldo Roque - SpeedCuber - 23.04.2021 21:51

private void OnlyNumbers(KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}

Ответить
Omcsesz
Omcsesz - 07.04.2021 01:58

Hello, 1BestCsharp blog!

I tried to use your solution, but there is no Keypress event defined for TextBox!
Maybe you are using an older version of .NET?

Ответить
Naiunn Online
Naiunn Online - 06.02.2020 11:07

why statement !char is meaning "NOT" but program allow input , i'm confusing. please advise.

Ответить
Mz@Az
Mz@Az - 15.01.2020 07:47

Hi.can i know how to set a range for input allowed? for number

Ответить
Antros
Antros - 14.12.2019 23:00

Thanks. That'll be handy

Ответить
Asa Thompson
Asa Thompson - 04.10.2019 02:47

Earned my subscription.

Ответить
Kasun Charitha
Kasun Charitha - 18.04.2019 04:37

i want to add restriction for text box in maximum value and minimum value. how to code it?

Ответить
Mohamed Bassuny
Mohamed Bassuny - 22.03.2019 17:24

what if i want the number to be float 15.60 the " . " not accepted

Ответить
András Somogyi
András Somogyi - 25.02.2019 18:57

Thank you. It helped a lot.

Ответить
Alexander Esene
Alexander Esene - 06.11.2018 13:09

Thank you. Worked perfectly.

Ответить
Abdul Qadir
Abdul Qadir - 28.09.2018 09:05

not working for me.. :(

Ответить
Elemino Musgrove
Elemino Musgrove - 04.05.2018 02:21

Does any solution exist if you're making a UWP app with C#?

Ответить
Sarah Shakeel
Sarah Shakeel - 28.02.2018 23:35

plz reply quick

Ответить
Sarah Shakeel
Sarah Shakeel - 28.02.2018 23:28

can u tell me what to do if we have to use such validations for email in textbox?
jese mne email enter krane k ek textbox use kia hai,but email me to @ or fullstop "." bhi use hte hain to in 2 keywords ko kese daala ja skta hai using keypress?
kindly help as it is a lot urgent...

Ответить
Logos Maxima
Logos Maxima - 21.07.2017 02:50

doesnt accept white space

Ответить
Cynthia Demgne
Cynthia Demgne - 07.06.2017 16:06

Hello i am cynthia and i am looking for how to convert a double give in a toolbox to a string with c#
cann you please help me?

Ответить