Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to accept a float value in textbox?

that means accept only numeric values and '.' value

in desktop application
Posted
Updated 16-Nov-11 20:59pm
v2

Try this[^].
 
Share this answer
 
Use Compare validator
C#
<asp:textbox id="textbox11" runat="server" xmlns:asp="#unknown"></asp:textbox>
<asp:comparevalidator id="intValidator" runat="server" controltovalidate="textbox1" operator="DataTypeCheck" type="float" errormessage="Value must be float" xmlns:asp="#unknown" />
 
Share this answer
 
put one regular expression in front of that textbox and control that text box which ever it is.
goto properties and do this....
validate expression: ^([0-9].[0-9])*$
 
Share this answer
 
1. Are you using WinForms or ASP.NET ?

2. Do the float values have a fixed format: i.e., are there always going to be the same number of digits before the decimal point ?

Use of a MaskedTextBox is not indicated when the format of input varies, like the number of digits before the decimal point.

Another strategy is to intercept the keystrokes being put into a TextBox as they are typed, and limit them to only digits and the decimal point.

And, as one answer points out here: if you want to let the user type anything and check later, validation can be done, using a RegEx.

You need to specify more clearly what your question is.
 
Share this answer
 
If you are using asp.net, Use compare validator

XML
<asp:CompareValidator ID="CompareValidator1" runat="server"ControlToValidate="TextBox1" ErrorMessage="Value must be double";CompareValidator"style="top: 70px; left: 418px; position: absolute; height: 19px; width: 113px"Type="Double"></asp:CompareValidator>


If you are using windows form, handle the KeyPress event of the TextBox
for numeric values only.
 
Share this answer
 

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