1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
// ------------------------
// COULEURS DES CHAMPS
// ------------------------
var couleurValide = "orange";
var couleurInvalide = "grey";
// ------------------------
// URL
// ------------------------
var complementURL = "local/";
//var complementURL = "www/";
function extraireServeurPath() {
var path = document.location.href;
var reg = new RegExp("^(http\:\/\/[A-Za-z0-9\.\-]{1,30}\/)", "g");
var server = path.split(reg)[1];
return server+complementURL
}
// ------------------------
// EXPRESSIONS RATIONNELLES
// ------------------------
function definirType(type) {
switch(type) {
case "texte" :
var pattern = "^[A-Za-z\ \-]{1,20}$";
break;
case "numerique" :
var pattern = "^[0-9\.]{1,20}$";
break;
case "alphanumerique" :
var pattern = "^[A-Za-z0-9\.\-\_\ \']{1,50}$";
break;
case "liste" :
var pattern = "^[A-Za-z\ \.\,\-\;\_\:]{1,50}$";
break;
case "date" :
var pattern = "^[0-9]{2}/[0-9]{2}/[0-9]{4}$";
break;
case "telephone" :
var pattern = "^[0-9]{10}$";
break;
case "cp" :
var pattern = "^[0-9]{5}$";
break;
case "email" :
var pattern = "^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$";
break;
default :
alert('Type de champ invalide !')
break;
}
return pattern
}
// ------------------------
// FONCTION DE VERIFICATION
// ------------------------
function verificationChamp(champ,type) {
var expression = new RegExp(definirType(type))
if (expression.test(champ.value)) {
champ.style.color = couleurValide;
//champ.style.background = "url("+extraireServeurPath()+"style/images/tinyApply.png) no-repeat right";
champ.style.backgroundImage = "url("+extraireServeurPath()+"style/images/tinyApply.png)";
champ.style.backgroundRepeat = "no-repeat";
champ.style.backgroundPosition = "right";
} else {
champ.style.color = couleurInvalide;
champ.style.backgroundImage = "url("+extraireServeurPath()+"style/images/tinyApply.png)";
champ.style.backgroundRepeat = "no-repeat";
champ.style.backgroundPosition = "right";
//champ.style.background = "url("+extraireServeurPath()+"style/images/tinyCross.png) no-repeat right";
}
}
// ------------------------
// VERIFICATION GLOBALE DU FORMULAIRE
// ------------------------
function verificationGlobale(nomFormulaire,tabChamps) {
for (var i=0;i<=count(tabChamps);i++) {
alert(tabChamps[i])
}
} |
Partager