If there are no empty fields, then the following code validates the first name by calling the static method Match of the Regex class, passing both the string to validate and the Regular Expression as arguments. This object contains a Success property that indicates whether a method Match's first argument matches the pattern specified by the Regular Expression in the second argument.
It’s been around for decades, you surely have seen it: You fill in the form, click submit, and then you either see everything went well, or see the form again, with error messages. However, there still are two pieces of the puzzle missing: . The way you want to display the errors will, in a way, influence how you represent them. With that, let’s see how a form component could use this function.
If there is a match, then the event handler proceeds to validate the first name.
This process continues until the event handler validates the user input in all the Text Boxes or until a validation fails.
If one or more fields are empty then the program displays a message to the user that all fields must be filled in before the program can validate the input information.
The code above calls the first Name Text Box's Focus method to place the cursor in the first Name Text Box.