C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » Windows »

textbox validation


Posted Date: 01 Jan 2009      Posted By: sreejith      Member Level: Gold     Points: 1   Responses: 8



I want to Validate textbox with only integer value in windows form using c#.net





Responses

Author: Gaurav Agrawal    01 Jan 2009Member Level: DiamondRating: 1 out of 5     Points: 1

use masked textbox in windows application for do this

GA

Thanks & Regards,

Gaurav Agrawal
Sr.Software Engineer
gaur1982@yahoo.com
09829373514



Author: Deepika Haridas    01 Jan 2009Member Level: DiamondRating: 3 out of 53 out of 53 out of 5     Points: 3

Hi,

Try this

private bool txtNumericStringIsValid()
{
if (txtpin.Text == string.Empty)
{
return true;
}
char[] testArr = txtpin.Text.ToCharArray();
bool testBool = false;
for (int i = 0; i < testArr.Length; i++)
{
if (!char.IsNumber(testArr[i]))
{
testBool = true;
}
}
return testBool;
}



Thanks & Regards,
Deepika
Editor

If U want to shine like a SUN..First U have to burn like the SUN!!
Need a Guide? Join my mentor program..



Author: divya    01 Jan 2009Member Level: GoldRating: 1 out of 5     Points: 1

Hi
Try this
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="Please enter a numeric value guests ." ValidationExpression="^\d+(\.\d+)?$"
>*</asp:RegularExpressionValidator>



Author: Rahul    01 Jan 2009Member Level: SilverRating: 3 out of 53 out of 53 out of 5     Points: 3

In the keypress event of textbox write below code..

If (char.IsDigit()) then
e.handled=true
else
e.handled=false
End if

The keypress event will be be fired every time u press any of the key

and TextBox will accept only numbers u have entered.



Author: Ranish    02 Jan 2009Member Level: BronzeRating: 1 out of 5     Points: 1

if (!Char.IsControl(e.KeyChar))
{
e.Handled = !Char.IsDigit(e.KeyChar);
}



Author: AMARJIT SINGH    07 Jan 2009Member Level: GoldRating: 1 out of 5     Points: 1

Hello friend,

Here is a solution i am writing to you.
The code restricts as user to enter any letter in the textbox,i.e. only digits can be entered by this code.

Here is the solution ---------------

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

If e.KeyChar.IsDigit(e.KeyChar) = False And Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) = 13 Then
MsgBox("Please focus to next control.")
Exit Sub
End If
e.Handled = True
MsgBox("Please Enter only digits")
End If
End Sub




---------

Enjoy programming.
AMARJIT SINGH.



Author: Sajith G.S.    14 Jan 2009Member Level: BronzeRating: 1 out of 5     Points: 1

Hello friend,

Use Ajax FilteredTextBoxExtender to do this,

<ajaxToolkit:FilteredTextBoxExtender id="FilteredTextBoxExtender2" runat="server" TargetControlID="txtCCNo" FilterType="Numbers"></ajaxToolkit:FilteredTextBoxExtender>

(FilterType="Numbers") means that textbox only allows integer values..



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Spliting NAd merging Audio files
Previous : Validating datagridview column
Return to Discussion Forum
Post New Message
Category: Windows

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use