//Basic Form Field Verification Script
//-------------------------------------
//-------------------------------------
//Author: Alex Robinson
//Date: 23rd January 2009
//Version 1.1
//Revisions: Address RegExs Added Total 5
//Revision Date: 19th February 2009
//-------------------------------------
//-------------------------------------

//Regular Expressions to be checked and modified as needed - use these for required fields
//FirstName /^([A-Za-z]+)$/
//LastName /^([a-zA-Z\s]+)$/
//email /^([0-9a-zA-Z]+)([0-9a-zA-Z\.-_]+)@([0-9a-zA-Z\.-_]+)\.([0-9a-zA-Z]+)/
//Phone /^([0-9]{5})-| ([0-9]{6})/
//Postcode /^[A-Za-z]{1,2}[0-9]{1,2}[A-Za-z]{0,1} [0-9]{1,2}[A-Za-z]{2}$/
//HouseNumber /^\-?[0-9]+$/
//AddressLine /^([a-zA-Z\s]+)$/
//Town /^([a-zA-Z\s]+)$/;
//County //^([a-zA-Z\s]+)$/;
//Empty Field /^\S+$/

//The FirstName Check Script

//This function checks the validity of the name format and alerts if incorrect

function match1(){

//sets up a variable with a regular expression which defines the required name format

var required_FirstName = /^([A-Za-z]+)$/;

//assigns the entered FirstName to a variable

var FirstName = document.getElementById('FirstName');

//tests whether the entered name matches the required name format

var format_match1= required_FirstName.test(FirstName.value);


//if else statement defines action if match or no match


if (format_match1)

{
	
}
	
	else
{	window.alert ("First Name - Invalid Entry. Please re-enter using alphabetic characters only.");
	
}
	
}

//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------

//The LastName Check Script

//This function checks the validity of the name format and alerts if incorrect

function match2(){

//sets up a variable with a regular expression which defines the required name format

var required_LastName = /^([a-zA-Z\s]+)$/;

//assigns the entered LastName to a variable

var LastName = document.getElementById('LastName');

//tests whether the entered name matches the required name format

var format_match2= required_LastName.test(LastName.value);


//if else statement defines action if match or no match


if (format_match2)

{
	
}
	
	else
{	window.alert ("Last Name - Invalid Entry. Please re-enter using alphabetic characters only.");
	
}
	
}

//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------


//The email Check Script

//This function checks the validity of the email format and alerts if incorrect

function match3(){

//sets up a variable with a regular expression which defines the required email format

var required_email = /^([0-9a-zA-Z]+)([0-9a-zA-Z\.-_]+)@([0-9a-zA-Z\.-_]+)\.([0-9a-zA-Z]+)/;

//assigns the entered email to a variable

var email = document.getElementById('email');

//tests whether the entered email matches the required email format

var format_match3= required_email.test(email.value);


//if else statement defines action if match or no match


if (format_match3)

{
	
}
	
	else
{	window.alert ("Email address - Invalid email address - Please check and re-enter e.g. in the format 'joe@abc.net'.");
	
}
	
}


//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------


//The phone number Check Script

//This function checks the validity of the phone number format and alerts if incorrect

function match4(){

//sets up a variable with a regular expression which defines the required phone number format

var required_DayTel = /^([0-9]{5})-| ([0-9]{6})/;

//assigns the entered phone number to a variable

var DayTel = document.getElementById('DayTel');

//tests whether the entered phone number matches the required phone number format

var format_match4= required_DayTel.test(DayTel.value);


//if else statement defines action if match or no match


if (format_match4)

{
	
}
	
	else
{	window.alert ("Phone Number - Invalid number format. Please check and re-enter e.g. in the format '01234 567890'.");
	
}
	
}


//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------

//The House Number Check Script

//This function checks the validity of the house number format and alerts if incorrect

function match5(){

//sets up a variable with a regular expression which defines the required house number format

var required_HouseNumber = /^\-?[0-9]+$/;

//assigns the entered HouseNumber to a variable

var HouseNumber = document.getElementById('HouseNumber');

//tests whether the entered house number matches the required number format

var format_match5= required_HouseNumber.test(HouseNumber.value);


//if else statement defines action if match or no match


if (format_match5)

{
	
}
	
	else
{	window.alert ("House/Flat Number - Invalid format. Please check and re-enter. For flats i.e 5D enter 5 in number and D in name.");
	
}
	
}



//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------

//The House Name Check Script

//This function checks the validity of the house name format and alerts if incorrect

function match6(){

//sets up a variable with a regular expression which defines the required house name format

var required_HouseName = /^([a-zA-Z\s]+)$/;

//assigns the entered HouseName to a variable

var HouseName = document.getElementById('HouseName');

//tests whether the entered house name matches the required name format

var format_match6= required_HouseName.test(HouseName.value);


//if else statement defines action if match or no match


if (format_match6)

{
	
}
	
	else
{	window.alert ("House/Flat Name - Invalid format. Please check and re-enter.");
	
}
	
}

//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------

//The AddressLine Check Script

//This function checks the validity of the AddressLine format and alerts if incorrect

function match7(){

//sets up a variable with a regular expression which defines the required AddressLine format

var required_AddressLine1 = /^([a-zA-Z\s]+)$/;

//assigns the entered AddressLine1 to a variable

var AddressLine1 = document.getElementById('AddressLine1');

//tests whether the entered AddressLine1 matches the required name format

var format_match7= required_AddressLine1.test(AddressLine1.value);


//if else statement defines action if match or no match


if (format_match7)

{
	
}
	
	else
{	window.alert ("Address Line 1 - Invalid format. Please check and re-enter.");
	
}
	
}

//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------

//The Town/City Check Script

//This function checks the validity of the Town/City format and alerts if incorrect

function match8(){

//sets up a variable with a regular expression which defines the required Town/City format

var required_Town = /^([a-zA-Z\s]+)$/;

//assigns the entered Town/City to a variable

var Town = document.getElementById('Town');

//tests whether the entered Town/City matches the required name format

var format_match8= required_Town.test(Town.value);


//if else statement defines action if match or no match


if (format_match8)

{
	
}
	
	else
{	window.alert ("Town/City - Invalid format. Please check and re-enter.");
	
}
	
}

//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------

//The Postcode Check Script

//This function checks the validity of the Postcode format and alerts if incorrect

function match9(){

//sets up a variable with a regular expression which defines the required Postcode format

var required_Postcode = /^[A-Za-z]{1,2}[0-9]{1,2}[A-Za-z]{0,1} [0-9]{1,2}[A-Za-z]{2}$/;

//assigns the entered Postcode to a variable

var Postcode = document.getElementById('Postcode');

//tests whether the entered Postcode matches the required name format

var format_match9= required_Postcode.test(Postcode.value);


//if else statement defines action if match or no match


if (format_match9)

{
	
}
	
	else
{	window.alert ("Postcode - Invalid format. Please check and re-enter in the format AA12 1AA.");
	
}
	
}



//--------------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------


//The Submit Check Script
//To check that any required form fields are completed and valid prior to submission

function submitcheck()

{

//sets up a variable with a regular expression which defines the required name format

var required_FirstName = /^([A-Za-z]+)$/;

//assigns the entered FirstName to a variable

var FirstName = document.getElementById('FirstName');

//tests whether the entered name matches the required name format

var format_match1= required_FirstName.test(FirstName.value);


//sets up a variable with a regular expression which defines the required name format

var required_LastName = /^([a-zA-Z\s]+)$/;

//assigns the entered LastName to a variable

var LastName = document.getElementById('LastName');

//tests whether the entered name matches the required name format

var format_match2= required_LastName.test(LastName.value);


//sets up a variable with a regular expression which defines the required email format

var required_email = /^([0-9a-zA-Z]+)([0-9a-zA-Z\.-_]+)@([0-9a-zA-Z\.-_]+)\.([0-9a-zA-Z]+)/;

//assigns the entered email to a variable

var email = document.getElementById('email');

//tests whether the entered email matches the required email format

var format_match3= required_email.test(email.value);


//sets up a variable with a regular expression which defines the required phone number format
//not used here as phone number is not a required field

//var required_DayTel = /^([0-9]{5})-| ([0-9]{6})/;

//assigns the entered phone number to a variable

//var DayTel = document.getElementById('DayTel');

//tests whether the entered phone number matches the required phone number format

//var format_match4= required_DayTel.test(DayTel.value);


//sets up a variable with a regular expression which defines the required house number format

var required_HouseNumber = /^\-?[0-9]+$/;

//assigns the entered house number to a variable

var HouseNumber = document.getElementById('HouseNumber');

//tests whether the entered house number matches the required number format

var format_match5= required_HouseNumber.test(HouseNumber.value);


//sets up a variable with a regular expression which defines the required house name format

var required_HouseName = /^([a-zA-Z\s]+)$/;

//assigns the entered house name to a variable

var HouseName = document.getElementById('HouseName');

//tests whether the entered house name matches the required name format

var format_match6= required_HouseName.test(HouseName.value);


//sets up a variable with a regular expression which defines the required AddressLine1 format
//NOTE - this regex is only checking that the field is not blank

var required_AddressLine1 = /^([a-zA-Z\s]+)$/;

//assigns the entered AddressLine1 to a variable

var AddressLine1 = document.getElementById('AddressLine1');

//tests whether the entered AddressLine1 matches the required format

var format_match7= required_AddressLine1.test(AddressLine1.value);


//sets up a variable with a regular expression which defines the required Town/City format

var required_Town = /^([a-zA-Z\s]+)$/;

//assigns the entered Town/City to a variable

var Town = document.getElementById('Town');

//tests whether the entered Town/City matches the required format

var format_match8= required_Town.test(Town.value);


//sets up a variable with a regular expression which defines the required Postcode format

var required_Postcode = /^[A-Za-z]{1,2}[0-9]{1,2}[A-Za-z]{0,1} [0-9]{1,2}[A-Za-z]{2}$/;

//assigns the entered Postcode to a variable

var Postcode = document.getElementById('Postcode');

//tests whether the entered Postcode matches the required format

var format_match9= required_Postcode.test(Postcode.value);


var complete=true;

//if else statement defines action to be taken according to conditions



if ((format_match1)&&(format_match2)&&(format_match3)&&(((format_match5)||(fomat_match6))||((format_match5)&&(fomat_match6)))&&(format_match7)&&(format_match8)&&(format_match9))
		{	
		window.alert ("Thank You - your enquiry has been submitted.");
		complete=true;
		}
		else
		{window.alert ("Please enter data in the required field or check that the data entered is in the correct format.");
		complete=false;
		}
		
return complete;
		
}
			
	
		


	
		
//-------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------




