Click here to Skip to main content
14,695,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a text box which accepts hours.It will allow only numeric and decimal points.And max of only single decimal point is allowed.

So when the user enters single decimal point in the starting of the textbox without any other digits, and on click of Ok an alert message should be displayed.

How can i achieve that in C#?
Posted

1 solution

If you are only checking if the input is valid when the user clicks OK, try something like this:
double userinput = 0;
bool isvalid = double.TryParse(yourtextbox.text, out userinput);
if (!isvalid)
{
   MessageBox.Show("Invalid Entry"); //Etc.
}
else
{
   MessageBox.Show("You entered: " + userinput.ToString());
}


Hope this helps :-)
   
Comments
Member 10593922 6-Mar-14 4:46am
   
thank you it was helpful for me.
Mitchell J. 6-Mar-14 5:14am
   
Glad to help. :) Did you want to accept the solution using the button?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900