Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 212273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:10:17+00:00 2026-05-11T18:10:17+00:00

This supposedly easy task gave me some headache. I simply want to let the

  • 0

This supposedly easy task gave me some headache. I simply want to let the user enter any text that succeeds float.TryParse into a Textboxish control.

I could use a normal TextBox and check the Text in some btnOK_Click, but this is obviously lame. Also, there is a nice built-in MaskedTextBox control, but I failed to set it’s mask to be equal to float.TryParse. Also, it seems to check for validity only when a focus change occurs.

Digging around on the net brought some interesting ideas, but none of them as nice as I would like.

How did you solve this problem? Did I simply miss an obvious solution, or do I have to implement this functionality myself?

I’m aware of a few similar threads on SO, but there was no feasible solution to be found.

Update: Yes, WinForms.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:10:17+00:00Added an answer on May 11, 2026 at 6:10 pm

    Edit

    Well that makes it alot easier… Just add a Validating Event Handler to your textbox
    and do the TryParse in the code behind. If its invalid, prompt the user as such.

    Validating will fire when the user is finished typing and moves focus from the TextBox so if you need to do on the fly checking, you could handle the TextChanged or on of the KeyPress/KeyUp Event handlers instead

    Original

    Is this in asp.net or winforms/wpf

    If its asp.net, you could use a combination of RegularExpressionValidator (to account for comma seperation, 1 decimal point, etc…) and a RangeValidator to set the min/max values for a float.

    Aside from that, the only way to guarantee it would be to wrap the textbox in an updatepanel, stick a CustomServerValidator on it, and in the server validate function, do a TryParse on the TextBox.Text value, if it succeeds, IS VALID, if it fails, NOT VALID

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In SQL 2008 I've this easy-but-bad-write sp that works: ALTER PROCEDURE [dbo].[paActualizaCapacidadesDeZonas] AS BEGIN
This is supposedly a very easy question, but I just can't seem to find
I'm writing a Qt application that needs to save some settings to the user's
I can't seem to find solutions to this supposedly simple problem /bug, so here
This piece of code is supposed to go through a list and preform some
Easy question, I know. But failing nonethless! In C sharp you can simply type:
I'm trying to compile the SndObj library from the source. Supposedly it's as easy
I'm pretty new to cron jobs so this might be an easy answer but
For the this task I'm supposed to find all the names of actors who
I'm trying to create a VSIX installer for a WPF control. Its supposedly easy,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.