function validateEmail(email) {
var reg = /^(([^<>()[\]\\.,;:\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,}))$/;
return reg.test(email);
}
$(document).ready(function() {
$("#adminForm").submit(function() {
var err=0;
$("#minimail").html('');
var email1val = $("#email").val();
var email2val = $("#mailconf").val();
var mailvalid1 = validateEmail(email1val);
var mailvalid2 = validateEmail(email2val);
if(mailvalid1 == false) { $("#champ_email").removeClass("green"); $("#champ_email").addClass("red"); err++; } else if (mailvalid1 == true){
$("#champ_email").removeClass("red");
$("#champ_email").addClass("green");
$.ajax({
url: 'controleur.php?case=email',
data: 'email='+ email1val,
success: function(reponse) {
if (reponse!="ok") {
$("#champ_email").removeClass("green");
$("#champ_email").addClass("red");
$("#minimail").html('Email déjà utilisé');
err++;
} else {
$("#minimail").html('');
}
}
});
}
if(mailvalid2 == false) { $("#champ_confemail").removeClass("green"); $("#champ_confemail").addClass("red"); err++; } else if(mailvalid2 == true){ $("#champ_confemail").removeClass("red"); $("#champ_confemail").addClass("green"); }
if(email1val!=email2val) { $("#champ_confemail").removeClass("green"); $("#champ_confemail").addClass("red"); err++; }
var prenomval = $("#prenom").val(); var prenomlen = prenomval.length;
if(prenomlen < 2) { $("#champ_prenom").removeClass("green"); $("#champ_prenom").addClass("red"); err++; } else if(prenomlen >= 2){ $("#champ_prenom").removeClass("red"); $("#champ_prenom").addClass("green"); }
var nomval = $("#nom").val(); var nomlen = nomval.length;
if(nomlen < 2) { $("#champ_nom").removeClass("green"); $("#champ_nom").addClass("red"); err++; } else if(nomlen >= 2){ $("#champ_nom").removeClass("red"); $("#champ_nom").addClass("green"); }
var telephoneval = $("#telephone").val(); var telephonelen = telephoneval.length;
if(telephonelen < 2) { $("#champ_telephone").removeClass("green"); $("#champ_telephone").addClass("red"); err++; } else if(telephonelen >= 2){ $("#champ_telephone").removeClass("red"); $("#champ_telephone").addClass("green"); }
$("#minipass1").html('');
$("#minipass2").html('');
var pass1val = $("#pass").val();
$.ajax({
url: 'controleur.php?case=pass',
data: 'pass='+ pass1val,
success: function(reponse) {
if (reponse!="ok") {
$("#champ_pass").removeClass("green");
$("#champ_pass").addClass("red");
$("#minipass1").html('Au moins 1 majuscule, 1 minuscule et 1 chiffre et 6 caractères mini');
err++;
} else {
$("#champ_pass").removeClass("red");
$("#champ_pass").addClass("green");
$("#minipass1").html('');
}
}
});
var pass2val = $("#vpass").val();
if(pass1val!=pass2val || pass1val.length<6 || pass2val.length<6 ) { $("#champ_vpass").removeClass("green"); $("#champ_vpass").addClass("red"); $("#minipass2").html('Mots de passe différents'); err++; }
var cgv = "";
if($('input[name=valide]').is(':checked')) {
$("#validation").removeClass("red");
$("#validation").addClass("green");
} else {
$("#validation").removeClass("green");
$("#validation").addClass("red");
err++;
}
if (err>0) { $('#champs').modal('show'); return false; }
});
});