function submitForm(form) { if (checkIt(form)) { form.submit(); } } function checkIt(form) { //variables that store contents of e-mail address and question fields for validation //Create a variable like these for each text or textarea field that you want to require patron to complete //Then add a check for the contents of the variable where indicated (see "Make sure the E-mail address // contains some data" for an example) var email = form.email.value; var email2 = form.emailconf.value; //variable for value of e-mail confirmation field var question = form.question.value; var lib; //variable that contains contents of message to display to patron if required field(s) are blank var msg = ''; if (form.library.selectedIndex >= 0) { lib = form.library.options[form.library.selectedIndex].value; } if (lib == null) { lib=form.library.value; } // Make sure the E-mail address field contains some data if(email.length < 1) { if(msg.length > 0) msg+=', '; msg += 'Dirección de correo-e'; } // Make sure the Confirm e-mail address field contains some data if(email2.length < 1) { if(msg.length > 0) msg+=', '; msg += 'Confirme la dirección de correo-e'; } //Make sure the Question field contains some data if(question.length < 1) { if(msg.length > 0) msg+=', '; msg += 'Consulta'; } //Make sure Reason for research has been selected //Use this as a prototype for validating other drop-down list fields if (form.field3.selectedIndex == 0) { if (msg.length >0) msg+= ', '; msg += 'Motivo de la investigación'; } //Make sure "May we forward your question..." has been answered //Use this as a prototype for validating other radio button fields for (i=0, n=form.field4.length; i0) msg+= ', '; msg += '¿Podemos enviar su consulta?'; } //Display alert box for patron; he/she left at least one required field blank if (msg != '') { alert("Uno o más de los campos requeridos están en blanco\r\n" + msg); return false; } if(lib.length < 1) { alert("La biblioteca que provee este formulario tiene un error en el formulario. Sírvase ponerse en contacto con ellos y avisarles que hay un problema\r\n"); return false; } if (emailCheck(email, true)) { //the next four lines only apply to forms with a confirmation e-mail field. Remove or comment //them out if you do not need them or the script will not run properly. if (email != email2) { alert("Verifique la dirección de correo-e y confírmela. No corresponden.") return false; } //end e-mail confirmation check return true; } else { return false; } } function emailCheck (emailStr, alertflag) { var emailPat=/^(.+)@(.+)$/ var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]" var validChars="\[^\\s" + specialChars + "\]" var quotedUser="(\"[^\"]*\")" var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/ var atom=validChars + '+' var word="(" + atom + "|" + quotedUser + ")" var userPat=new RegExp("^" + word + "(\\." + word + ")*$") var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$") var matchArray=emailStr.match(emailPat) if (matchArray==null) { if (alertflag) alert("La direcció de correo-e parece incorrecta (compruebe ubicación de @ y puntos).") return false } var user=matchArray[1] var domain=matchArray[2] // See if "user" is valid if (user.match(userPat)==null) { // user is not valid if (alertflag) alert("El nombre del usuario no parece v´lido.") return false } /* if the e-mail address is at an IP address (as opposed to a symbolic host name) make sure the IP address is valid. */ var IPArray=domain.match(ipDomainPat) if (IPArray!=null) { // this is an IP address for (var i=1;i<=4;i++) { if (IPArray[i]>255) { if (alertflag) alert("La dirección IP de destino no es válida.") return false } } return true } // Domain is symbolic name var domainArray=domain.match(domainPat) if (domainArray==null) { if (alertflag) alert("El nombre del dominio no parece válido.") return false } var atomPat=new RegExp(atom,"g") var domArr=domain.match(atomPat) var len=domArr.length musExp = /.museum/ isMus = domain.search(musExp) if ( ( (domArr[domArr.length-1].length < 2) || (domArr[domArr.length-1].length > 6) ) || (domArr[domArr.length-1].length == 5) || ( (domArr[domArr.length-1].length == 6) && (isMus == -1) ) ) { // the address must end in a two, three, or four letter word or .museum if (alertflag) alert("La dirección debe terminar en las tres o cuatro letras de un dominio, las dos letras de un país, o en .museum.") return false } // Make sure there's a host name preceding the domain. if (len<2) { var errStr="A esta dirección de correo-e le falta el nombre del servidor." if (alertflag) alert(errStr) return false } // If we've gotten this far, everything's valid! return true; }