C# Tutorial 57: TextBox which accepts only numbers in C#

Sdílet
Vložit
  • čas přidán 3. 05. 2013
  • ★★★Top Online Courses From ProgrammingKnowledge ★★★
    Python Programming Course ➡️ bit.ly/2vsuMaS ⚫️ bit.ly/2GOaeQB
    Java Programming Course ➡️ bit.ly/2GEfQMf ⚫️ bit.ly/2Vvjy4a
    Bash Shell Scripting Course ➡️ bit.ly/2DBVF0C ⚫️ bit.ly/2UM06vF
    Linux Command Line Tutorials ➡️ bit.ly/2IXuil0 ⚫️ bit.ly/2IXukt8
    C Programming Course ➡️ bit.ly/2GQCiD1 ⚫️ bit.ly/2ZGN6ej
    C++ Programming Course ➡️ bit.ly/2V4oEVJ ⚫️ bit.ly/2XMvqMs
    PHP Programming Course ➡️ bit.ly/2XP71WH ⚫️ bit.ly/2vs3od6
    Android Development Course ➡️ bit.ly/2UHih5H ⚫️ bit.ly/2IMhVci
    C# Programming Course ➡️ bit.ly/2Vr7HEl ⚫️ bit.ly/2W6RXTU
    JavaFx Programming Course ➡️ bit.ly/2XMvZWA ⚫️ bit.ly/2V2CoAi
    NodeJs Programming Course ➡️ bit.ly/2GPg7gA ⚫️ bit.ly/2GQYTQ2
    Jenkins Course For Developers and DevOps ➡️ bit.ly/2Wd4l4W ⚫️ bit.ly/2J1B1ug
    Scala Programming Tutorial Course ➡️ bit.ly/2PysyA4 ⚫️ bit.ly/2PCaVj2
    Bootstrap Responsive Web Design Tutorial ➡️ bit.ly/2DFQ2yC ⚫️ bit.ly/2VoJWwH
    MongoDB Tutorial Course ➡️ bit.ly/2LaCJfP ⚫️ bit.ly/2WaI7Ap
    QT C++ GUI Tutorial For Beginners ➡️ bit.ly/2vwqHSZ
    ★★★ Online Courses to learn ★★★
    Get 2 FREE Months of Unlimited Classes from skillshare - skillshare.eqcm.net/r1KEj
    Data Science - bit.ly/2lD9h5L | bit.ly/2lI8wIl
    Machine Learning - bit.ly/2WGGQpb | bit.ly/2GghLXX
    Artificial Intelligence - bit.ly/2lYqaYx | bit.ly/2NmaPya
    MERN Stack E-Degree Program - bit.ly/2kx2NFe | bit.ly/2lWj4no
    DevOps E-degree - bit.ly/2k1PwUQ | bit.ly/2k8Ypfy
    Data Analytics with R - bit.ly/2lBKqz8 | bit.ly/2lAjos3
    AWS Certification Training - bit.ly/2kmLtTu | bit.ly/2lAkQL1
    Projects in Java - bit.ly/2kzn25d | bit.ly/2lBMffs
    Machine Learning With TensorFlow - bit.ly/2m1z3AF | bit.ly/2lBMhnA
    Angular 8 - Complete Essential Guide - bit.ly/2lYvYRP
    Kotlin Android Development Masterclass - bit.ly/2GcblsI
    Learn iOS Programming Building Advance Projects - bit.ly/2kyX7ue
    ★★★ Follow ★★★
    My Website - www.codebind.com
    DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!
    c# - How do I make a textbox that only accepts numbers?
    c# - How do I generate a textbox that only accepts numbers?
    Allow user to only enter numbers in textbox and if character
    Textbox only number or decimal
    Textbox must accept only numbers and
    Textbox only accepting numbers in C# windows application
    C# Numbers Only Textbox - Visual C#
    Textbox to accept only numbers in C# windows Forms C# .NET
    textbox accept only numbers

Komentáře • 63

  • @randomhappyguy6719
    @randomhappyguy6719 Před 7 lety +11

    .Net has upgraded and int representation of characters are no longer needed. We can use code like this:
    char ch = e.KeyChar;
    if (!char.IsDigit(ch) &&
    ch != Convert.ToChar(Keys.Back) &&
    ch != Convert.ToChar(Keys.Delete))
    e.Handled = true;
    Here we use a Convert.ToChar(Object object) to directly convert a Keys enumeration variable to a character, then compare.

  • @avi12
    @avi12 Před 10 lety

    I was looking for this so much time. *Subscribed*

  • @muraligsn
    @muraligsn Před 8 lety +25

    Thanks for the video..but please stop wiggling the mouse.

    • @kaimemes
      @kaimemes Před 5 lety +5

      what you gotta do wit ha big fat mouse
      *WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE WIGGLE*

  • @ZCProductions211
    @ZCProductions211 Před 10 lety +5

    If Anyone is wondering how to make it possible to enter a period like 1.70 then add
    && ch != 46 to the if statement after the ch != 8. I had to do this for the program i am making.

  • @23anonymous46
    @23anonymous46 Před 7 lety

    It's really help me so much, thank you very much guy C#

  • @HearthsTavern
    @HearthsTavern Před 7 lety +2

    Great Video! Thanks for the upload
    How can I make this accept decimal?

  • @Verses01
    @Verses01 Před 7 lety

    Awesome Thank you!!!

  • @CalebRussell1
    @CalebRussell1 Před 6 lety

    You helped me so much. Thank you bhai

  • @funtaro
    @funtaro Před 8 lety

    Thanks, it's help me alot

  • @oblivionX000
    @oblivionX000 Před 6 lety

    Is that possible with decimals as well? Cause I would try to input a period for the decimal which then the code prevents me from doing so.

  • @brv0102
    @brv0102 Před 7 lety

    thanks, bro!

  • @AhsanAli-uu9ui
    @AhsanAli-uu9ui Před 6 lety

    i cant found your Remaining lectures of this course in this Channel. what i do? please give me link of complt tutorial of this course. Thanks

  • @Kaizer-qe7kk
    @Kaizer-qe7kk Před 7 lety

    One question. How do I get data from the textbox as an integer?
    I need to perform a calculation with the data obtained.

  • @shovikanand3214
    @shovikanand3214 Před 5 lety

    very knowledgeful video....but i want to add more concept in this, here e is object of keypressEventArgs Class. & this class has 2 properties namely keychar & handled. keychar gives u key pressed by user. & handled doesnt allows wrong entry into textboxes. here char is structures. & Isdigit, Isletter, IsDigitorLetter,Issymbol .....are its properties..
    hence we use , char.Isdigit(e.keychar) & similary e.handled= true; restrict wrong entry & e.handled= false; to allow entry in textbox. hope u get benifited after reading this...

  • @yameen_yasin
    @yameen_yasin Před 5 lety

    thankew sir aap explane bhi ache krte ho or kaam to hota he aap k acha hai

  • @hafizullahmutahidi264
    @hafizullahmutahidi264 Před 6 lety

    Thank You So So Much

  • @amazingbandproyects3253

    Works : ) ..Thank you so much.....Regards from Costa Rica : )

  • @adrianm.4873
    @adrianm.4873 Před 4 lety

    Thank you!

  • @rodrigo-vl7bi
    @rodrigo-vl7bi Před 4 lety

    thanks for showing this solution, but im sure there must be a simplier way, al keep looking for it

  • @atquoc9071
    @atquoc9071 Před 5 lety

    Thanks for video

  • @vihangasilva
    @vihangasilva Před 7 lety

    Thank you

  • @MonderMurshed
    @MonderMurshed Před rokem

    THANK U BRO!

  • @deano2187
    @deano2187 Před 7 lety

    Thank you senpai

  • @prodbyfys
    @prodbyfys Před 6 lety

    Thanks Bro

  • @YukthiJayakody
    @YukthiJayakody Před 8 lety

    Thanks a lot....

  • @bayaromer5850
    @bayaromer5850 Před 6 lety

    thank you soooooooo much

  • @TheTrueKailash
    @TheTrueKailash Před 8 lety

    thank you

  • @MrFerny82
    @MrFerny82 Před 11 lety

    Hi, your tutorial is great but i'm running into an issue and I want to use number an at the end the character -, how to i do that? my example should look like this only 102030-10
    Thanks

  • @MegaMaliak
    @MegaMaliak Před 5 lety

    Hi how do i make validation to allow format like prices ONLY? 999.99 is the precise amount i need. Nothing more than that, but can't go below 0.

  • @intelligentcoding689
    @intelligentcoding689 Před 3 lety

    Amazing. thanks

  • @LivinExtreme
    @LivinExtreme Před 10 lety +2

    what if I paste it doesn't work then

  • @3dwinarcip394
    @3dwinarcip394 Před 3 měsíci

    Niceee❤❤❤ Thanks

  • @mikaillim9978
    @mikaillim9978 Před 11 lety +1

    hii.. why you can using DateTimePicker ? it simple :D

  • @dennisJNT
    @dennisJNT Před 6 lety

    nice man..

  • @IAmESG
    @IAmESG Před 7 lety +2

    Or this:
    if (System.Text.RegularExpressions.Regex.IsMatch(tb11.Text, "[^0-9-]")) // only accepts 0-9 and negative
    {
    MessageBox.Show("Please enter numbers only!");
    tb11.Clear();
    }

  • @ariii39
    @ariii39 Před 4 lety

    Thanks!!!!

  • @muhdzikrie8682
    @muhdzikrie8682 Před 3 lety

    thanks

  • @kristiancagaoan2223
    @kristiancagaoan2223 Před 9 lety +3

    THANKS BRUH

  • @user-xg7hi5mh3g
    @user-xg7hi5mh3g Před 3 lety

    Thnak u for your video its great i just have a small isssue with this filtraion how can we for example just allow numbers between 0 and 13 ?

    • @user-pm4ng4wf8d
      @user-pm4ng4wf8d Před 3 lety

      استخدم شرط if لتحديد أصغر و أكبر قيمة

  • @girishbawaskar3775
    @girishbawaskar3775 Před 7 lety +1

    and if i want only char than ?????

  • @iiN1GH7M4R3ii
    @iiN1GH7M4R3ii Před 5 lety

    thank youuuuu

  • @malthesrensen4953
    @malthesrensen4953 Před 5 lety

    Seems wierd that this isen't in the library already. When pasting, you can still add text to the field for example, so that has to be fixed aswell. Seems like a lot of work for something that should've been in the library already

  • @kmuralikrishna1582
    @kmuralikrishna1582 Před 5 lety

    if we want combination of numbers and string ?

  • @gnscode7988
    @gnscode7988 Před 4 lety

    helpfull

  • @idsoftware7
    @idsoftware7 Před 4 lety

    how about decimals ?

  • @claytonvolner5950
    @claytonvolner5950 Před 2 lety

    Great video. Thanks for the help

  • @Soundtech98
    @Soundtech98 Před 8 lety

    Still doesn't prevent the user from pasting directly into the text box...

  • @thiagosarraf7265
    @thiagosarraf7265 Před 5 lety

    where are you from? I'm brazilian

  • @wunnathaw
    @wunnathaw Před 6 lety

    that is cool..but I input 012 or 1.11 .It cannot validate .

    • @jobijose8354
      @jobijose8354 Před 5 lety

      this is not an validation process infact we can block some sort of data thats all

  • @bluehornet6752
    @bluehornet6752 Před 10 lety +1

    Here's a routine that's worked well for me...
    private void CharValidation_KeyDown(object sender, KeyEventArgs e)
    {
    // Rejects any keys not in the range of 0-9 (by ASCII number),
    // the Delete key or the Back key
    if ((e.KeyValue < 48 || e.KeyValue > 57) && e.KeyCode != Keys.Delete
    && e.KeyCode != Keys.Back
    {
    e.SuppressKeyPress = true;
    SystemSounds.Beep.Play();
    }
    }

    • @Volln0v
      @Volln0v Před 10 lety

      This works, but not if a user used the num pad. This is what I used for my program, it's kind of lengthy but it allowed for numpad decimal, period, numlock, and arrow keys. Probably not the most efficient way, but it works.
      if ((e.KeyValue < 48 || e.KeyValue > 57) && e.KeyCode != Keys.OemPeriod && e.KeyCode != Keys.NumLock && e.KeyCode != Keys.Decimal && e.KeyCode != Keys.Delete
      && e.KeyCode != Keys.Back && e.KeyCode != Keys.NumPad0 && e.KeyCode != Keys.NumPad1 && e.KeyCode != Keys.NumPad2 && e.KeyCode != Keys.NumPad3 && e.KeyCode != Keys.NumPad4 && e.KeyCode != Keys.NumPad5 && e.KeyCode != Keys.NumPad6 && e.KeyCode != Keys.NumPad7 && e.KeyCode != Keys.NumPad8 && e.KeyCode != Keys.NumPad9 && e.KeyCode != Keys.Left && e.KeyCode != Keys.Right)
      {
      e.SuppressKeyPress = true;
      SystemSounds.Beep.Play();
      }

  • @sheetalvishwakarma2697

    Voice is not auditable