.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Common Function to Validate Decimal Numbers in Text Box (Dot should be appear once in the text box)

Posted By:Prasanti Prusty       Posted Date: January 29, 2010    Points: 10    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

Common Function to Validate Decimal Numbers in Text Box (Dot should be appear once in the text box)
 

'Usage : On KeyPress Event we Can call the function to Validate the Text Box.
'Parameter : Textbox & KeyPressEventArgs
'Output : It Handels when Dot entered 2 time in the text box


 Shared Sub ChkDot(ByVal ctxt As TextBox, ByVal x As System.Windows.Forms.KeyPressEventArgs)
        If (Char.IsControl(x.KeyChar) Or Char.IsDigit(x.KeyChar) = True) Or x.KeyChar = "." Then
            If ctxt.Text.IndexOf(".") <> -1 And x.KeyChar = "." Then
                x.Handled = True
            End If
        Else
            x.Handled = True
        End If
    End Sub

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend