/** * Validates that input's value is correct email address */ function validateEmail(elem) { var str = ""; if (elem.value) { str = new String(elem.value); } else { str = new String(elem); } if (window.RegExp) { var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)"; var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,4})(\\]?)$"; var reg3str = "\"([^\"]+)\"\\s+<{1}([A-z]{1}[A-z0-9\\x2d\\.]*[A-z0-9]{1}@[A-z0-9\\x2d\\.]*[A-z-9]{1}\\.[A-z]{2,5})>{1}"; var reg1 = new RegExp(reg1str); var reg2 = new RegExp(reg2str); var reg3 = new RegExp(reg3str); if (!reg1.test(str) && (reg2.test(str) || reg3.test(str))) return true; return false; } else { if (str.indexOf("@") >= 0) return true; return false; } } String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); } /** * returns string with all leading and trailing characters * eliminated. */ function trim(str){ var s = new String(str); //trailing spaces while (s.length>0 && isSpaceCharacter(""+s.charAt(s.length-1))){ s = s.substring(0,s.length-1); } //leading spaces while (s.length>0 && isSpaceCharacter(""+s.charAt(0))){ s = s.substring(1); } return s } var spaces = " \t\r\n"+String.fromCharCode(160); function isSpaceCharacter(ch){ return spaces.indexOf(ch) >-1; } function isEmpty(elem){ return trim(elem.value).length==0; } function validateForm(){ if(f.email){ if(!f.alreadyreg.checked){ if(isEmpty(f.firstname)){ alert("Please enter first name"); f.firstname.focus(); return false; } if(isEmpty(f.lastname)){ alert("Please enter last name"); f.lastname.focus(); return false; } } if(!isEmpty(f.email) && !validateEmail(f.email)){ alert("Please enter valid email address"); f.email.focus(); return false; } if(!f.alreadyreg.checked){ if(f.email.value!=f.confirmemail.value){ alert("Email addresses do not match"); f.confirmemail.focus(); return false; } if(isEmpty(f.password)){ alert("Please enter password"); f.password.focus(); return false; } if(isEmpty(f.confirmpassword)){ alert("Please confirm password"); f.confirmpassword.focus(); return false; } if(f.password.value!=f.confirmpassword.value){ alert("Passwords do not match"); f.confirmpassword.focus(); return false; } if(isEmpty(f.login)){ alert("Please enter online name"); f.login.focus(); return false; } } } if(isEmpty(f.quest)){ alert("Please enter your question"); f.quest.focus(); return false; } f.submit(); } function showFields(x){ for(var i=1;i<10;i++){ var fil = document.getElementById('field'+i); if(fil!=null){ if(x.checked){ fil.style.display='none'; }else{ fil.style.display='block'; } } } }