Dim str Allowed Chars As String = "0123456789() - " If Len(txt Telephone.Text) = 0 Then Exit Sub Else For i = 0 To Len(txt Telephone.For our Visual Basic applications, we will need to work a little harder to ensure that the input is valid, because we will need to define and code our own validation rules.In a software project of any size, the task of determining what valid data is usually undertaken long before any code is written, and is part of an initial requirements analysis phase.If this occurs, the event handler will display a message to tell the user that the telephone number entered is invalid, restore the focus to the Telephone field, and exit the subroutine.Run the program and test the code by entering an invalid telephone number.
Data validation rules can also make an application more user friendly, since they enable the program to warn the user immediately when there is a problem rather than simply allowing them to continue entering data until the program crashes or some other problem occurs.
Even so, we can think in general terms about the kind of data validation required for a typical application, and how it might be implemented.
Some common data validation requirements are outlined below.
There are many ways in which validation can be carried out, and it is down to analysts and software developers to decide what kind of validation is required and how to implement it.
To demonstrate some simple validation techniques, we will create a data entry form of the type typically found on a web page.