Questo è il file "validation.js"
codice:
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* Title : Form Validation 2013
* Author : HeLL-WeB
*
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
// *** INIZIO ***
function Controlla(){
var cognome = document.forms.modulo.cognome.value;
var nome = document.forms.modulo.nome.value;
var email = document.forms.modulo.email.value;
var telefono = document.forms.modulo.telefono.value;
var citta = document.forms.modulo.citta.value;
var captcha = document.getElementById("captcha");
var codice = document.forms.modulo.codice.value;
var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/; //Indirizzo email valido
var num_reg_exp = /^([0-9])+$/; //Inserimento solo Numeri
var reg_exp = /^([a-zA-Z0-9])+$/; //Inserimento Lettere e Numeri
var let_reg_exp = /^([a-zA-Z])+$/; //Inserimento solo Lettere
var alertMsg = 'Il form contiene uno o pi\371 errori:\n';
/*
\371 = ù
\350 = è
\340 = à
*/
Errore="";
if(cognome==""){Errore=alertMsg += ' -> Il campo Cognome \350 richiesto\n';
document.forms.modulo.cognome.value = '';
}
if(nome==""){Errore=alertMsg += " -> Il campo Nome \350 richiesto\n";
document.forms.modulo.nome.value = '';
}
if(!email_reg_exp.test(email)){Errore=alertMsg += " -> Il campo E-mail deve contenere un indirizzo email valido\n";
document.forms.modulo.email.value = '';
}
if(!num_reg_exp.test(telefono)){Errore=alertMsg += " -> Il campo Telefono deve contenere solo numeri\n";
document.forms.modulo.telefono.value = '';
}
if(citta==""){Errore=alertMsg += " -> Il campo Citt\340 \350 richiesto\n";
document.forms.modulo.citta.value = '';
}
if (document.forms.modulo.accetto.checked==false){Errore=alertMsg += " -> Il checkbox Autorizzo trattamento dati deve essere selezionato\n";
}
if(codice != captcha){Errore=alertMsg += " -> Il campo Captcha non corrisponde\n";
document.forms.modulo.codice.value = '';
}
if(Errore==""){
document.forms.modulo.action = 'invia.php';
document.forms.modulo.submit();
}else{
alert(Errore);
}
}
// *** FINE ***