What is the best way to validate a users input? I need to validate a "Name" entered in a textbox, as well as an enetered "Score". Could someone please help me with this.
Validation of userinput
Collapse
X
-
-
-
Code:Private Sub txtNewName_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles textNewName.Validating If Not (txtNewName.Text Like "A-Za-z") Then e.Cancel = True txtNewName.Select(0, txtNewName.Text.Length) MessageBox.Show (txtNewName, "Invalid name") End If End Sub
Last edited by Frinavale; Apr 13 '10, 03:21 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.Comment
-
Validating user input from a textbox. Alpha characters
I'm not sure if this is the correct code to use for validating user input. Would someone correct me please. Thank you.
Code:Private Sub txtNewName_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles textNewName.Validating If Not (txtNewName.Text Like "A-Za-z") Then e.Cancel = True txtNewName.Select(0, txtNewName.Text.Length) MessageBox.Show (txtNewName, "Invalid name") End If End Sub
Comment
-
When you created the project that you're working on....did you create it as an MVC ASP.NET project or did you create it as a normal ASP.NET application/website?
I suggest you create a class that you can use to validate your user input with.
For example:
Code:Class myValidation Public Shared Function UserNameIsValid(ByVal userName As String) Dim isValid As Boolean = False If (someRequirementsAreMet) Then isValid = True End If Return isValid End Function '...other functions End Class
In your page code you would have:
Code:'In Button Click event: If (myValidation.UserNameIsValid(txt_username.Text) AndAlso ...other validation Then 'update database or whatever you need to do Else 'indicate to the user that there were errors. End If
Comment
-
rWarren1: You have started 4 separate threads for this same topic/issue. Please stop doing that. It makes it hard to coordinate efforts to help you.
[]I was told I need to be in VB.Net forum. I am developing a program in visual studio 2008. [/]
Thanks Visual Studio supports several different programming languages. There are forums here for each language: C-Sharp, Visual Basic, Visual C++ and so on. In the future you need to post your questions in the correct forum if you expect the most experienced people to see them so they can help you.Comment
Comment