
// Parameters. 
// String (to be searched for disallowed characters)
// fieldName (Name of the input box calling the function. for information purposes.
// required (true if its a mandatory field)
function checkFieldGeneral(string,fieldName,required){


	if(required && string.length == 0){
		alert(fieldName + ' is a mandatory field. Please enter a value for the ' + fieldName);
	}else{
		var re;
		if(required){
			re = /^([0-9a-zA-ZΑΙΝΣΪ ΔΛΟΦάαινσϊδλοφό',.-/\s]){1,1000}$/;
		}else{
			re = /^([0-9a-zA-ZΑΙΝΣΪ ΔΛΟΦάαινσϊδλοφό',.-/\s]){0,1000}$/;
		}

		if(re.test(string)){ // If there are no illegal characters in string
			return true;
		}else{
			// string is halved and tested until the single offending character is left. The first illegal
			// character is the one which will be found.

			if(string.length > 1){ 

				if(!re.test(string.substring(0,Math.round(string.length/2)))){ // Problem is on the left half

					checkFieldGeneral(string.substring(0, Math.round(string.length/2)),fieldName);

				}else{
					checkFieldGeneral(string.substring(Math.round(string.length/2),string.length),fieldName); //Problem on the right.

				}

			}else{
				alert('The character (' + string +  ') has been entered into the ' + fieldName + ' input box. \n\nThis character is not allowed in this input field.\n\n\Please try again.');
				return false;

			}

		}
	}
}

// Parameters. 
// String (to be searched for disallowed characters)
// fieldName (Name of the input box calling the function. for information purposes.
// required (true if its a mandatory field)
function checkFieldAddress(string,fieldName,required){

	if(required && string.length == 0){
		alert(fieldName + ' is a mandatory field. Please enter a value for the ' + fieldName)
	}else{
		var re;
		if(required){
			re = /^([0-9a-zA-ZΑΙΝΣΪ ΔΛΟΦάαινσϊδλοφό'#,.-/&\s]){1,1000}$/;
		}else{
			re = /^([0-9a-zA-ZΑΙΝΣΪ ΔΛΟΦάαινσϊδλοφό'#,.-/&\s]){0,1000}$/;
		}

		if(re.test(string)){ // If there are no illegal characters in string
			return true;
		}else{
			// string is halved and tested until the single offending character is left. The first illegal
			// character is the one which will be found.

			if(string.length > 1){ 

				if(!re.test(string.substring(0,Math.round(string.length/2)))){ // Problem is on the left half

					checkFieldAddress(string.substring(0, Math.round(string.length/2)),fieldName);

				}else{
					checkFieldAddress(string.substring(Math.round(string.length/2),string.length),fieldName); //Problem on the right.

				}

			}else{
				alert('The character (' + string +  ') has been entered into the ' + fieldName + ' input box. \n\nThis character is not allowed in this input field.\n\n\Please try again.');
				return false;

			}

		}
	}
}


// Parameters. 
// String (to be searched for disallowed characters)
// fieldName (Name of the input box calling the function. for information purposes.
// required (true if its a mandatory field)
function checkFieldName(string,fieldName, required){

	if(required && string.length == 0){
		alert(fieldName + ' is a mandatory field. Please enter a value for the ' + fieldName)
	}else{
		var re;
		if(required){
			re = /^([0-9a-zA-ZΑΙΝΣΪ ΔΛΟΦάαινσϊδλοφό',.-/&]){1,100}$/;
		}else{
			re = /^([0-9a-zA-ZΑΙΝΣΪ ΔΛΟΦάαινσϊδλοφό',.-/&]){0,100}$/;
		}

		if(re.test(string)){ // If there are no illegal characters in string
			return true;
		}else{
			// string is halved and tested until the single offending character is left. The first illegal
			// character is the one which will be found.

			if(string.length > 1){ 

				if(!re.test(string.substring(0,Math.round(string.length/2)))){ // Problem is on the left half

					checkFieldName(string.substring(0, Math.round(string.length/2)),fieldName);

				}else{
					checkFieldName(string.substring(Math.round(string.length/2),string.length),fieldName); //Problem on the right.

				}

			}else{
				alert('The character (' + string +  ') has been entered into the ' + fieldName + ' input box. \n\nThis character is not allowed in this input field.\n\n\Please try again.');
				return false;

			}

		}
	}
}


// Parameters. 
// String (to be searched for disallowed characters)
// fieldName (Name of the input box calling the function. for information purposes.
// required (true if its a mandatory field)
function checkFieldTelephone(string,fieldName,required){

	if(required && string.length == 0){
		alert(fieldName + ' is a mandatory field. Please enter a value for the ' + fieldName)
	}else{
		var re;
		if(required){
			re = /^([0-9 +()]){1,100}$/;
		}else{
			re = /^([0-9 +()]){0,100}$/;
		}

		if(re.test(string)){ // If there are no illegal characters in string
					return true;
		}else{
			// string is halved and tested until the single offending character is left. The first illegal
			// character is the one which will be found.

			if(string.length > 1){ 

				if(!re.test(string.substring(0,Math.round(string.length/2)))){ // Problem is on the left half

					checkFieldTelephone(string.substring(0, Math.round(string.length/2)),fieldName);

				}else{
					checkFieldTelephone(string.substring(Math.round(string.length/2),string.length),fieldName); //Problem on the right.

				}

			}else{
				alert('The character (' + string +  ') has been entered into the ' + fieldName + ' input box. \n\nThis character is not allowed in this input field.\n\n\Please try again.');
				return false;

			}

		}
	}
}


// Parameters. 
// String (to be searched for disallowed characters)
// fieldName (Name of the input box calling the function. for information purposes.
// required (true if its a mandatory field)
function checkFieldZipCode(string,fieldName,required){

	if(required && string.length == 0){
		alert(fieldName + ' is a mandatory field. Please enter a value for the ' + fieldName)
	}else{
		var re;
		if(required){
			re = /^([0-9a-zA-ZΑΙΝΣΪ ΔΛΟΦάαινσϊδλοφό]){1,100}$/;
		}else{
			re = /^([0-9a-zA-ZΑΙΝΣΪ ΔΛΟΦάαινσϊδλοφό]){0,100}$/;
		}

		if(re.test(string)){ // If there are no illegal characters in string
			return true;
		}else{
			// string is halved and tested until the single offending character is left. The first illegal
			// character is the one which will be found.

			if(string.length > 1){ 

				if(!re.test(string.substring(0,Math.round(string.length/2)))){ // Problem is on the left half

					checkFieldZipCode(string.substring(0, Math.round(string.length/2)),fieldName);

				}else{
					checkFieldZipCode(string.substring(Math.round(string.length/2),string.length),fieldName); //Problem on the right.

				}

			}else{
				alert('The character (' + string +  ') has been entered into the ' + fieldName + ' input box. \n\nThis character is not allowed in this input field.\n\n\Please try again.');
				return false;

			}

		}
	}
}


// Parameters. 
// String (to be searched for disallowed characters)
// fieldName (Name of the input box calling the function. for information purposes.
// required (true if its a mandatory field)
function checkFieldEmail(string,fieldName,required){


	if(!required && string.length == 0){
		return true;
	}else if(required && string.length == 0){
		alert(fieldName + ' is a mandatory field. Please enter a value for the ' + fieldName)
		return false;
	}else{
		var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

		if(re.test(string)){ // If there are no illegal characters in string
			return true;
		}else{
			alert('This is not a valid email address. Please check the email address format you have entered.');
			return false;
		}
	}
}

	  
// Parameters. 
// String (to be searched for disallowed characters)
// fieldName (Name of the input box calling the function. for information purposes.
// required (true if its a mandatory field)
function checkFieldNumber(string,fieldName,required){

	if(required && string.length == 0){
		alert(fieldName + ' is a mandatory field. Please enter a value for the ' + fieldName)
	}else{
		var re;
		if(required){
			re = /^([0-9]){1,100}$/;
		}else{
			re = /^([0-9]){0,100}$/;
		}

		if(re.test(string)){ // If there are no illegal characters in string
					return true;
		}else{
			// string is halved and tested until the single offending character is left. The first illegal
			// character is the one which will be found.

			if(string.length > 1){ 

				if(!re.test(string.substring(0,Math.round(string.length/2)))){ // Problem is on the left half

					checkFieldNumber(string.substring(0, Math.round(string.length/2)),fieldName);

				}else{
					checkFieldNumber(string.substring(Math.round(string.length/2),string.length),fieldName); //Problem on the right.

				}

			}else{
				alert('The character (' + string +  ') has been entered into the ' + fieldName + ' input box. \n\nThis character is not allowed in this input field.\n\n\Please try again.');
				return false;

			}

		}
	}
}

