ASP.NET Validation Tutorial
This article describes how to quickly add thorough validation of postcodes, telephone
numbers and email addresses, far beyond what can be achieved using only standard
regular expression validators.
To follow this tutorial you will need to have installed our
ASP.NET Data Capture &
Validator pack, which you can download free of charge. You will also need to
have registered for an account with us and arranged
with your account manager to get access to the
Postcode Lookup,
Telephone Validation,
Mobile Validation
and Email Validation services. You
can call us now on 0151 355 4555 to arrange these details and ensure that you are
given the services that are best for you.
Validating Postcodes
If you're using our ASP.NET AddressCapture control for everywhere that your users enter
addresses, you don't need worry about validating postcodes as this functionality is
already built into that control. However, if you've got a simple set of text boxes,
you can use our PostcodeValidator control to ensure they are correct.
Open your web page in the Visual Studio designer. After installing the validator controls,
you should now have a Data8 tab in your toolbox.

Drag & drop a PostcodeValidator control from the Data8 toolbox onto your page to
start adding postcode validation.

In the Properties window, set up the ControlToValidate and ErrorMessage properties as you
would for any normal validator control. Also set the Username, Password and Licence
properties to the appropriate values for your account - if you are unsure of these values,
please contact your account manager.

That's it! Any values entered into the text box will be validated as correct postcodes,
and you don't need to change any code.
Validating Telephone & Mobile Numbers
If your website allows users to enter telephone numbers you're probably validating them
with a regular expression validator, but by using our data-driven validator you can be
sure that the number that has been entered has actually been allocated for use and contains
the correct number of digits for that particular exchange - most exchanges use 10 digit
numbers while others use only 9. Validating telephone numbers to this level of detail
ensures that only accurate data is captured, and typing errors or deliberate attempts to
enter invalid numbers are prevented. For mobile numbers, the validator goes further to
check that the exact number that has been entered exists and is assigned to a valid mobile.
Open your web page in the Visual Studio designer. After installing the validator controls,
you should now have a Data8 tab in your toolbox.

Drag & drop a TelephoneValidator control from the Data8 toolbox onto your page to
start adding telephone number validation.

In the Properties window, set up the ControlToValidate and ErrorMessage properties as you
would for any normal validator control. Also set the Username and Password
properties to the appropriate values for your account - if you are unsure of these values,
please contact your account manager.
The UseTelephoneValidation and UseMobileValidation properties control whether the standard telephone
number validation rules or the mobile validation rules are applied. If both are set, the standard
telephone number validation rules are applied first, and the mobile validation rules are applied
only when these tests are passed and the number appears to be a mobile number. By default, only
the standard telephone number validation rules are applied, so ensure you set UseMobileValidation
to True to ensure the most accurate data. Note that you will need access to both the telephone
validation and mobile validation web services in order to set both of these properties to True.
The ExcludeUnlikelyNumbers property controls whether numbers that are commonly entered to get around
validation rules should be marked as invalid. However, some of these numbers may actually be in use,
so use this option with caution. This property only has any effect when UseTelephoneValidation is
true.
The ExcludeUnavailableMobiles property controls whether mobiles that are temporarily unavailable, i.e.
are either switched off or out of reception, but whose number is linked to an active subscription,
should be marked as invalid. This property only has any effect when UseMobileValidation is true.
That's it! Any values entered into the text box will be validated as correct telephone numbers,
and you don't need to change any code.
Validating Email Addresses
You probably already use regular expressions to validate any email addresses entered onto
your site, but that doesn't stop people entering invalid addresses such as mickeymouse@example.com.
Our Email Validation service goes a step further to check that the domain part of the address
is set up to receive email in order to prevent accidental typing errors (e.g. info@data-9.co.uk
rather than info@data-8.co.uk) as well as deliberately incorrect addresses.
Open your web page in the Visual Studio designer. After installing the validator controls,
you should now have a Data8 tab in your toolbox.

Drag & drop an EmailValidator control from the Data8 toolbox onto your page to
start adding email address validation.

In the Properties window, set up the ControlToValidate and ErrorMessage properties as you
would for any normal validator control. Also set the Username and Password
properties to the appropriate values for your account - if you are unsure of these values,
please contact your account manager.
That's it! Any values entered into the text box will be validated as correct email addresses,
and you don't need to change any code.