Start Validating phone numbers in

Validating phone numbers in

Note: If you are using WPF, I don't think there is a Masked Text Box in the base libraries, however there are extensions available on Nu Get which may provide similar functionality. Try Parse as davenewza recommended, but another alternative is to use the Visual Basic Is Numeric function from C#.

In addition to validating phone numbers, you can also identify whether the number is a landline or mobile, to assist ensuring compliance with regulators.

In that case, the previous value of the field is restored, and the user has to enter the data again.

This is not always desired (for more complicated data, it will probably be much easier to take a look, correct that one typo and continue with the rest of the form), so my preference is actually to mark the field so that the user knows which field needs to be corrected, and have the validation script not report a validation error back to the field: Using this method has implications on the form submission process: The form no longer can verify that the data is correct, so the submission function needs to do another round of validation to see if any of the required fields are not correct (one way to do that is to test all relevant fields to see if the text color is using the error color, or we can use global variables to store the validation state).

For numeric fields, there is a convenient way to validate a value range, but we want to select to run a custom validation script.

After the “Edit” button is clicked, a new window will open that allows us to edit the new script: This script also includes a check for an empty string, so that the user can wipe out a wrong string and start from scratch.

Another thing I like to do is to display the validation error message on the form in an otherwise hidden field: The problem with our last solution is that if the user saves a partially filled form, and picks it up at a later time, that error message that popped up is long gone, and the only indication that there is something wrong with the form is the modified field color.

So, having a text field contain that error message might be a good idea.

It saves time by early on checking for invalid phone numbers.