[C#] A TextBox that only accepts decimal/floating/double numbers

Sdílet
Vložit
  • čas přidán 25. 09. 2012
  • Our new facebook page : / 146893872037989
    Hey guys, in this video I'll show you how to make a TextBox only accepts decimal/floating/double numbers in C#.
    Make requests for our upcoming videos!

Komentáře • 61

  • @laijamanuel
    @laijamanuel Před 11 lety +2

    this is what I was looking for, thanks

  • @kennethstanley7438
    @kennethstanley7438 Před 9 lety

    Best answer I have found so far. Good job

  • @jvernice
    @jvernice Před 2 lety

    THANK YOU for a really simple solution that I have been looking for to validate my floating point text box.

  • @oscarbautista4156
    @oscarbautista4156 Před 3 lety

    Amazing solution to capture prices, thanks dude

  • @KryptonPix
    @KryptonPix Před 10 lety

    Wonderful, thank you for sharing this.

  • @viqUni
    @viqUni Před 10 lety

    Thanks bro! it was helpful to me

  • @paulvaz5846
    @paulvaz5846 Před 10 lety

    simple and nice, thanks for your grateful help... cheers

  • @rahulchowdarypinnaka
    @rahulchowdarypinnaka Před 4 lety

    That's really helpful. Thank you so much.

  • @electrious_46
    @electrious_46 Před 4 lety +1

    Thanks A lot man !!!

  • @uliseseduardofuentesvenado7112

    Great! Thanx. Really Helpful!

  • @iffi786
    @iffi786 Před 8 lety

    Thanks for a simple solution.

  • @zoltrixzoltrix
    @zoltrixzoltrix Před 11 lety

    It's Very Helpful. Thank You

  • @nguyenquyetthang8381
    @nguyenquyetthang8381 Před 3 lety

    That very helpful, thanks very much.

  • @caveman4191
    @caveman4191 Před 2 lety

    thanks! it helped me alot!

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

    ty a lot. Would like to know how to allow only 2-digits after the decimal point.
    but it was really helpfull. ^^

  • @aemarco
    @aemarco Před 8 lety +1

    Thanks for the easy solution ;)
    --> You should use CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0] instead of checking for a dot-char, because in other cultures e.g. in german it will be the ',' char for commas
    alternative:
    private void breiteQuer_KeyPress(object sender, KeyPressEventArgs e)
    {
    double result;
    char c = (char)e.KeyChar;
    string text = tb.Text + c;
    if (c != (char)Keys.Back && !double.TryParse(text, out result))
    {
    e.Handled = true;
    }
    }

  • @alexssandrolima
    @alexssandrolima Před 9 lety

    Muito bom, bem aproveitado.

  • @petrolheadsa
    @petrolheadsa Před 11 lety

    Great explanation thanks

  • @sbasalan
    @sbasalan Před 10 lety

    Amazing.. Thanks a lot

  • @semderoos123
    @semderoos123 Před 7 lety

    Nice video! Can you tell me how to add a comma to the filter?

  • @Sefree6
    @Sefree6 Před 10 lety

    Great video.

  • @caffo77
    @caffo77 Před 8 lety

    Nice, but what about negative numbers? I came up with the following code, which toggle the negative symbol when minus is pressed. The caret (prompt) is always sent at the end of the string.
    if (ch == '-')
    {
    if (Text.Length != 0 && Text[0] == '-')
    {
    Text = Text.Substring(1); //If we have a minus as first character, it removes it
    }
    else
    {
    Text = "-" + Text;
    }
    SelectionStart = Text.Length; //These 2 lines send the caret/prompt at the end of the string
    SelectionLength = 0; //Apparently superfluous, but it doesn't harm
    e.Handled = true;
    }

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

    Thanks, Fine -!!! easy solution for hard problem

  • @andrewtruckle1695
    @andrewtruckle1695 Před 10 lety

    Very helpful. Thank you. It might be usefult o allow for a hyper for negative numbers.
    One thing it would be nice to cater for is if the user "pastes" into the control. It will let us paste text content in.
    Also, what if we wanted to use this on more than one control. Can we somehow turn it into a control sow e don't replicate code?
    Thanks.

  • @didierleprince6106
    @didierleprince6106 Před 5 lety

    Thanks a lot from France

  • @keppu2661
    @keppu2661 Před 5 lety +1

    how to limit decimal place to 2 only while keypress?

  • @nealdorelis5703
    @nealdorelis5703 Před 2 lety

    Hi Charmy, It's a great video. I like it. do have video on how to convert number no c# database to string and display no windows form ? other question, do you also have video on how to display graph from database in c# using SQL Server

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

    totally cool !

  • @zal6616
    @zal6616 Před 8 lety

    Awesome!

  • @ProgramaInventarios
    @ProgramaInventarios Před 8 lety

    Thank you so much

  • @brv0102
    @brv0102 Před 7 lety

    thanks bro!

  • @valdeirjubertoni
    @valdeirjubertoni Před 8 lety

    Excelent!

  • @sergiopalazzi6033
    @sergiopalazzi6033 Před 5 lety

    Many thanks!

  • @pkspence
    @pkspence Před 11 lety

    I've got a minor modification that will only allow 2-digits after the decimal point, without a regex and no for loop. Can't cut 'n past, too many characters. Drop me a line if you're interested.

  • @JsRatteChannel
    @JsRatteChannel Před 11 lety

    Make sure that you use the KeyPress event and not the KeyDown event.

  • @Linkk2011
    @Linkk2011 Před 8 lety

    thanks man =)

  • @duchoang5114
    @duchoang5114 Před 3 lety

    Thanks a lot, it's helpfull :thumbup:

  • @illmtoloko
    @illmtoloko Před 9 lety

    thank you dude

  • @Harvinder864
    @Harvinder864 Před 10 lety

    Thanks Bro...

  • @888mrxxx
    @888mrxxx Před 11 lety

    How can i implement you code in WPF C#? Thank you so much if you can help....

  • @CarlosHernandez-eu8wi
    @CarlosHernandez-eu8wi Před 2 lety

    Thank you for sharing you knwlege

  • @kshitijbali6915
    @kshitijbali6915 Před 4 lety

    it helped. Thanks

  • @joa1paulo_
    @joa1paulo_ Před 9 lety

    Thanks!

  • @sevashpun
    @sevashpun Před 11 lety

    Thanks! =)

  • @CharnyCoding
    @CharnyCoding  Před 11 lety

    Get the ASCII code of '-' and add it to the condition!

  • @Kishara101
    @Kishara101 Před 4 lety

    Thanks 😀

  • @benmuhza3283
    @benmuhza3283 Před 10 lety

    Many thanks

  • @elginrepuela
    @elginrepuela Před 11 lety

    excellent...

  • @sagarjadhav-fo9vu
    @sagarjadhav-fo9vu Před 6 lety

    Thanks, Bro!!!...Sooo..Simle

  • @dasarislavo
    @dasarislavo Před 10 lety

    thanks man

  • @user-bu3kr8vb9r
    @user-bu3kr8vb9r Před 2 lety

    Спасибо большое))

  • @zaminhassnain7570
    @zaminhassnain7570 Před 5 lety

    Awesome (y)

  • @markvanwagoner4609
    @markvanwagoner4609 Před 10 lety

    very nice! thx!! saved me an hour

  • @mesaytesfa9875
    @mesaytesfa9875 Před 5 lety

    excellent

  • @marcosfalconi2765
    @marcosfalconi2765 Před 5 lety

    thank you

  • @smartcode1325
    @smartcode1325 Před 7 lety

    HOW I MAKE A TEXTBOX THAT ACCEPT ONLY EMAIL?

  • @dutchknexman
    @dutchknexman Před 11 lety

    my e.KeyChar doesnt work :S how can i fix that , it gives a error and evrything is right

  • @marcinmalacz518
    @marcinmalacz518 Před 4 lety

    If Textbox have . yet your example permit put other .

  • @fairecitta
    @fairecitta Před 10 lety

    i need it n.n