/*
Accepts UK mobile numbers only.  Can have country code prefix or not.  Spaces and hyphens trimmed out
07xx xxx xxxx
+447xx xxx xxxx
*/

function checkUKTelephone (telephoneNumber) {

  // Convert into a string and check that we were provided with something
  var telnum = telephoneNumber + " ";
  if (telnum.length == 1)  {
     telNumberErrorNo = 1;
     return false
  }
  telnum.length = telnum.length - 1;
  
  // Remove spaces from the telephone number to help validation
  while (telnum.indexOf(" ")!= -1)  {
    telnum = telnum.slice (0,telnum.indexOf(" ")) + telnum.slice (telnum.indexOf(" ")+1)
  }
  
  // Remove hyphens from the telephone number to help validation
  while (telnum.indexOf("-")!= -1)  {
    telnum = telnum.slice (0,telnum.indexOf("-")) + telnum.slice (telnum.indexOf("-")+1)
  }  

  var exp = /^(\+447)[\s]*(.*)$/;
  var exp2 = /^07[\s]*(.*)$/
  // Check if the number begins with "+447" or "07" - a valid UK mobile
  if ((exp.test(telnum) != true) && (exp2.test(telnum) != true)) {
     telNumberErrorNo = 2;
     return false;
  }
  
  // Now check that the remainder of the characters are digits
  exp = /^(\+447)[0-9]{9}$/
  exp2 = /^(07)[0-9]{9}$/
  if ((exp.test(telnum) != true) && (exp2.test(telnum) != true)) {
     telNumberErrorNo = 3;
     return false;
  }
  
  // Telephone number seems to be valid - return the stripped telehone number  
  return telnum;
}
var telNumberErrorNo = 0;
var telNumberErrors = new Array ();
telNumberErrors[0] = "Valid UK telephone number";
telNumberErrors[1] = "Please enter your mobile number";
telNumberErrors[2] = "Please supply a UK mobile number beginning with '07' or '+447'";
telNumberErrors[3] = "UK mobile numbers should contain 11 digits (or 13 digits if including country code)";