0151 355 4555

Ajax Telephone & Email Validation

This sample demonstrates using our email validation and telephone validation services to validate the details entered by a user before they submit a form.

For the sample to work, you must have first added the domain name of your website to your allowed list for your Ajax key.

This sample assumes you have a form on your website such as that shown below:

This form is set up with "d8validation" and "d8errortext" attributes as follows:

<input type="text" id="telephone" d8validation="inttelephone" d8errortext="Invalid telephone number" />

<input type="text" id="email" d8validation="email" d8errortext="Invalid email address" />

We can then apply these validation rules with one line of Javascript when the page is loaded:


or if your using Bootstrap then:


and you can now not submit the form without having a valid telephone number and email address.


There are two main parts to using this script - adding the d8validation and d8errortext attributes to the form elements that require validation and the Javascript code to apply the validation.

The form elements that require validation must be tagged with a d8validation attribute indicating what validation rules should be applied to it, and a d8errortext attribute that contains the error message to be used if those rules fail. The d8validation attribute can have any of the following values:

  • inttelephone - the field is validated using our international telephone validation service.
  • inttelephone+mobile - as inttelephone but using the more advanced mobile validation service when the telephone number is recognised as a mobile number.
  • inttelephone+line - as inttelephone but using the more advanced telephone line validation service when the telephone number is recognised as a UK landline.
  • inttelephone+mobile+line - uses the more advanced mobile and landline validation services where possible with a fallback to the basic telephone validation service for other numbers.
  • email - the field is validated using our email validation service at domain level, i.e. validating everything to the right of the @ sign.

After marking up the fields to be validated in this way you must call one of the following two methods to get the validation errors to be displayed:

  • initializePopupData8Validation - any validation errors are displayed in a popup message when the form is submitted.
  • initializeInlineData8Validation - any validation errors are displayed next to the fields that failed validation as soon as the user leaves that field.

Getting more control

You can override many of the details of how the validation script works to take fine control, for example:


For this script to work you must also include the following scripts in your page:

  • Data8 Ajax Loader at https(s)://webservices.data-8.co.uk/javascript/loader.ashx?key=your-ajax-key
  • Data8 Validation at http(s)://webservices.data-8.co.uk/javascript/validation_min.js

Full Example

The example above is created using this HTML & JavaScript:

<form action="/developers/sample-code/ajax-telephone-email-validation/success" data-toggle="validator" role="form" id="exampleForm">
		<div class="form-group">
			<label class="control-label" for="telephone">Telephone:</label>
			<div class="input-group">
				<span class="input-group-addon">
					<i class="fa fa-phone" aria-hidden="true"></i>
				<input type="tel" class="form-control" id="telephone" d8validation="telephone" d8errortext="Invalid telephone number" />

		<div class="form-group">
			<label class="control-label" for="email">Email:</label>
			<div class="input-group">
				<span class="input-group-addon">
					<i class="fa fa-envelope" aria-hidden="true"></i>
				<input type="text" id="email" class="form-control" d8validation="email" d8errortext="Invalid email address" />

		<div class="form-group">
			<button id="TryItNow1" disabled type="submit" class="btn btn-primary">Submit</button>

<script type="text/javascript">
	function loadRemoteJs(scriptUrlToLoad, callback) {
		var script = document.createElement("script");
		script.type = 'text/javascript';
		script.src = scriptUrlToLoad;
		if (callback)
			script.onload = callback;

	loadRemoteJs("https://webservices.data-8.co.uk/Javascript/Validation.js", function () {
		$(function () {

			$('#TryItNow1').prop('disabled', false);