
<!-- ********************************************************************************************-->
<!-- ******************************* Validation form script ************************************-->

<!-- This is a main function that calls a series of subfunctions, each of which checks a single form element for compliance. If the element complies than sufunction returns an empty string. Otherwise it returns a message describing the error and highlight appropriate element with yellow. -->
function validateFormOnSubmit(theForm) {
var reason = "";

//var firstName = document.getElementById('firstName');
//var secondName = document.getElementById('secondName');
//var email = document.getElementById('email');
//var phone = document.getElementById('phone');

//alert(firstName.value + " - " + theForm.realname) ;

//  reason += validateUsername(document.getElementById('firstName'));
//  reason += validateLastname(document.getElementById('secondName'));
  reason += validateEmail(document.getElementById('email'));
//  reason += validatePhone(document.getElementById('phone'));

  reason += jcapt();

    
  if (reason != "") {
    alert("Τα παρακάτω πεδία χρειάζονται διόρθωση:\n" + reason);
    return false;
  }

  return true;
}

<!-- The function below checks if the captcha field has been left empty or it is wrong.-->

function jcapt(){

var error = "";
var uword = hex_md5(document.getElementById(jfldid).value);

if (uword==cword[anum-1]) {
}
else {
        error = "Εισάγετε τον κωδικό όπως φαίνεται !!!!"
}
    return error;  

}



<!-- The function below checks if the user entered anything at all in the username field. If it’s not blank, we check the length of the string and permit only usernames that are between 5 and 15 characters. Next, we use the JavaScript regular expression /\W/ to forbid illegal characters from appearing in usernames. We want to allow only letters, numbers and underscopes. -->
function validateUsername(fld) {
    var error = "";
//    var illegalChars = /\s\W/; // allow letters, numbers, and underscores
//    var illegalChars = /\u039b\s\W/; // allow letters, numbers, and underscores AND WHITE SPACES
//  /[\u0374-\u03FF]+/

    var illegalChars = /[\u0374-\u03FF]\s[\u0374-\u03FF]\s[\W ]/; // allow letters, numbers, and underscores AND WHITE SPACES
																 // and GREEK LETTERS 


    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Δεν έχετε εισάγει το όνομα σας.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 35)) {
        fld.style.background = 'Yellow'; 
        error = "Το όνομα σας πρέπει να αποτελείται από 5 έως 35 χαρακτήρες.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "Το όνομα σας περιέχει χαρακτήρες που δεν επιτρέπονται !!!.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}


<!-- The function below checks if the user entered anything at all in the username field. If it’s not blank, we check the length of the string and permit only usernames that are between 5 and 15 characters. Next, we use the JavaScript regular expression /\W/ to forbid illegal characters from appearing in usernames. We want to allow only letters, numbers and underscopes. -->
function validateLastname(fld) {
    var error = "";
//    var illegalChars = /\s\W/; // allow letters, numbers, and underscores
//    var illegalChars = /\u039b\s\W/; // allow letters, numbers, and underscores AND WHITE SPACES
//  /[\u0374-\u03FF]+/

    var illegalChars = /[\u0374-\u03FF]\s[\u0374-\u03FF]\s[\W ]/; // allow letters, numbers, and underscores AND WHITE SPACES
																 // and GREEK LETTERS 


    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Δεν έχετε εισάγει το επώνυμο σας.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 35)) {
        fld.style.background = 'Yellow'; 
        error = "Το επώνυμο σας πρέπει να αποτελείται από 5 έως 35 χαρακτήρες.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "Το επώνυμο σας περιέχει χαρακτήρες που δεν επιτρέπονται !!!.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}


<!-- Next we want to see if the email address the user entered is real. This means that the input data must contain at least an @ sign and a dot (.). Also, the @ must not be the first character of the email address, and the last dot must at least be one character after the @ sign. At first we check if the user entered anything at all in the email field. Next, we use regular expression and the test() method to check the field for a compliance. Also we will use trim() function that will trim leading whitespace off the string. This won’t be perfect validation — it is possible to slip not compliant addresses by it — but it's normally good enough. -->

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "Δεν έχετε εισάγει το email σας.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Παρακαλώ εισάγετε μία έγκυρη διεύθυνση email.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "Η διεύθυνση email που έχετε εισάγει περιέχει μη έγκυρους χαρακτήρες.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

<!-- The function below checks if the phone number is valid. At first we use regular expression and the replace() method to clear out any spacer characters. Next, we use the isNaN() function to check if the phone number contain only numbers. At last we check the length of the string and permit only phone numbers with 10 digits.-->
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "Δεν έχετε εισάγει τηλέφωνο.\n";
        fld.style.background = 'Yellow';
	return error; 			// phone is not a required field in this form
    } else if (isNaN(stripped)) {
        error = "Το τηλέφωνο που έχετε εισάγει περιέχει μη έγκυρους χαρακτήρες\n";
        fld.style.background = 'Yellow';
    } else if (stripped.length != 10) {
        error = "Το τηλέφωνο πρέπει να αποτελείται από 10 ψηφία.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}
<!-- ********************************************************************************************-->

