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


Top 5 Contributors of the Month
Easy Web
Imran Ghani

Home >> Forum >> .NET Framework >> Post New QuestionBookmark and Share Subscribe to Forum

validation of a text box

Posted By: Santosh     Posted Date: August 25, 2012    Points:5   Category :.NET Framework
Hi

validation of a text box in key press event..

Thanks

Responses
Author: kamlesh             
Posted Date: August 27, 2012     Points: 20   

Hi,

take below function and call it when your you want.take errorprovider with your form.

private bool IsValidBackupSetName()
{
bool IsValid = true;
if (string.IsNullOrEmpty(txtBackuopJobName.Text))
{
errorProvider1.SetError(txtBackuopJobName, "Text Box is empyy");
IsValid = false;
}
else
{
errorProvider1.SetError(txtBackuopJobName, "");
}
return IsValid;
}

Thanks And Regards.
Kamlesh Nikam
Author: Baimey Rajesh             
Posted Date: August 28, 2012     Points: 20   

What validation do you need??

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
this is the key press event

Author: Baimey Rajesh             
Posted Date: August 28, 2012     Points: 20   

If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) _
Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
e.Handled = True
End If
If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
e.Handled = False
End If

Allow you to enter numb er only

Author: Baimey Rajesh             
Posted Date: August 28, 2012     Points: 20   

If (Microsoft.VisualBasic.Asc(e.KeyChar) < 65) _
Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 90) _
And (Microsoft.VisualBasic.Asc(e.KeyChar) < 97) _
Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 122) Then
'Allowed space
If (Microsoft.VisualBasic.Asc(e.KeyChar) <> 32) Then
e.Handled = True
End If
End If
' Allowed backspace
If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
e.Handled = False
End If
allow u to enter alphabe t only.

Please be more clear on ur requirement so that we can help u m ore

Author: Baimey Rajesh             
Posted Date: August 28, 2012     Points: 20   

Validation of number can be done as follows as well

If Char.IsDigit(e.KeyChar) = False And Char.IsControl(e.KeyChar) = False Then
e.Handled = True
MsgBox("Please enter valid number ")
End If


Author: Ravi Ranjan Kumar             
Posted Date: August 31, 2012     Points: 20   

Well what kind of validation do you want. you should ask appropriate question to be get your question solved easily and efficiently. There are many types of validation so better mention what validation do you want to have in your code.

Thanks & Regards
Ravi Ranjan Kumar
http://raviranjankr.wordpress.com


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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