//var id_version = 1; //var currentRub = 1; var validation = new formValidation(); validation.addInput("Votre message","document.carte.Body","text","4000","yes"); validation.addInput("Votre Nom","document.carte.NomFrom","text","200","yes"); validation.addInput("Votre Prenom","document.carte.PrenomFrom","text","200","yes"); validation.addInput("Votre E-Mail","document.carte.MailFrom","mail","250","yes"); validation.addInput("Nom du destinataire","document.carte.NomTo","text","200","yes"); validation.addInput("Prenom du destinataire","document.carte.PrenomTo","text","200","yes"); validation.addInput("Votre E-Mail","document.carte.MailFrom","mail","250","yes"); /*function Envoyer() { if (validation.validat()){ window.document.carte.submit(); } }*/ // CONSTRUCTEUR DE FORMVALIDATION function formValidation() { // PROPRIETE D'INSTANCE this.Index = new Array(); // METHODE D'INSTANCE this.addInput = formValidation_addInput; this.validat = formValidation_validat; } // RAJOUTE UN OBJET INPUTVALIDATION A L'OBJET FORMVALIDATION function formValidation_addInput(nom,input,contenu,longueur,obligatoire) { this.Index[this.Index.length] = new inputValidation(nom,input,contenu,longueur,obligatoire); } // VALIDE L'ENSEMBLE DES OBJETS INPUTVALIDATION DE L'OBJET FORMVALIDATION function formValidation_validat() { for (i = 0; i < this.Index.length; i++) { valide = this.Index[i].checkEntry(); if (valide) { continue; } else { break; } } return valide; } // CONSTRUCTEUR DES OBJETS INPUTVALIDATION function inputValidation(nom,input,contenu,longueur,obligatoire) { this.name =nom; this.input =input; this.contentType = contenu; this.length = longueur; this.compulsory = obligatoire; this.checkEntry = inputValidation_checkEntry; return this; } // VALIDE LE CONTENU D'UN OBJET INPUTVALIDATION function inputValidation_checkEntry() { inputToTest = eval(this.input); valide=true; if ((inputToTest.type=="file")||(inputToTest.type=="text")||(inputToTest.type=="textarea") || (inputToTest.type=="password")) { valueToTest=inputToTest.value; // VALEUR NUMERIQUE if ((valide==true)&&(this.contentType=="numeric")&&((valueToTest-0)!=valueToTest)) { valide=false; alert("Une valeur num�rique est attendue pour le champ \""+this.name+"\"."); } // URL DE TYPE HTTP OU MAILTO if ((valide==true)&&(valueToTest!="")&&(this.contentType=="url")) { var mailtoReg = new RegExp("[Mm][Aa][Ii][Ll][Tt][Oo]:(.)+[@](.)+[\.](.)+"); var urlReg = new RegExp("[Hh][Tt][Tt][Pp]://(.)+[\.](.)+[\.](.)+"); var valideMailto=true; var valideUrl=true; if (!mailtoReg.test(valueToTest)) { valideMailto=false; } if (!urlReg.test(valueToTest)) { valideUrl=false; } if (!valideMailto && !valideUrl) { valide=false; alert("La valeur du champs \""+this.name+"\" n'est pas une url valide.\n\nhttp://xxx.xxx.xxx\nmailto:xxx@xxx.xxx"); } } // ADRESSE MAIL if ((valide==true)&&(valueToTest!="")&&(this.contentType=="mail")) { var mailtoReg = new RegExp("[a-z0-9._-]+[@][a-z0-9_-]+[\.][a-z0-9._-]+"); if (!mailtoReg.test(valueToTest)) { valide=false; alert("La valeur du champs \""+this.name+"\" n'est pas une adresse mail valide."); } } // UN CODE POSTAL if ((valide==true)&&(this.contentType=="CodePostal")&&(valueToTest!="")) { if (valueToTest.length != this.length) { valide=false; alert("Le champ \""+this.name+"\" doit poss�der exactement " +this.length+" caract�res."); } else if ((valueToTest-0)!=valueToTest) { valide=false; alert("Une valeur num�rique est attendue pour le champ \""+this.name+"\"."); } else if ((valueToTest.substring(0,2)=="00")||(valueToTest.substring(0,2)=="96")||(valueToTest.substring(0,2)=="97")||(valueToTest.substring(0,2)=="98")||(valueToTest.substring(0,2)=="99")) { valide=false; alert("Le \""+this.name+"\" saisi n'est pas valide."); } } // TROP DE CARACTERES if ((valide==true)&&(valueToTest.length > this.length)) { valide=false; alert("Il ne peut y avoir plus de "+this.length+" caract�res pour le champ \""+this.name+"\"."); } // CHAMP OBLIGATOIRE re2 = / /gi; valueToTestb = valueToTest.replace(re2,""); if ((valide==true)&&(this.compulsory=="yes")&&(valueToTestb.length==0)) { valide=false; alert("Une valeur est requise pour le champ \""+this.name+"\"."); } if (valide==false) { // Pour certains champs je ne veux pas qu'il les selectionne blnSelectIt = true; ListNotSel = new Array(); ListNotSel[0] = "document.Modform.Titre2"; ListNotSel[1] = "document.Modform.Titre3"; ListNotSel[2] = "document.Modform.Titre4"; for (lns=0;lns