var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31); function checkDate(form,name) { var x = form.elements; var day = parseInt(x[name+"_day"].options[x[name+"_day"].selectedIndex].value); var month = parseInt(x[name+"_month"].options[x[name+"_month"].selectedIndex].value); var year = parseInt(x[name+"_year"].options[x[name+"_year"].selectedIndex].value); if (!day || !month || !year) return false; if (year/4 == parseInt(year/4)) monthLength[1] = 29; if (day > monthLength[month-1]) return false; monthLength[1] = 28; var now = new Date(); now = now.getTime(); //NN3 var dateToCheck = new Date(); dateToCheck.setYear(year); dateToCheck.setMonth(month-1); dateToCheck.setDate(day); var checkDate = dateToCheck.getTime(); var futureDate = (now < checkDate); var pastDate = (now > checkDate); return true; } function validate_simpleCheckEmail(email){ //add new domains to this array when they are available var validDomainArray = new Array("de", "com", "edu", "org", "net", "gov", "tv","info", "name"); //parse domain out of email without . at beginning var domain = email.substring( email.lastIndexOf(".") + 1, email.length ); //don't allow empty fields if( email == "" ) return false; //basic format checking if (email.indexOf("@") <= 0 || // @ symbol found at least once and not first char email.indexOf(".") <= 0 || // . symbol found at least once and not first char email.indexOf(' ') != -1 // no spaces found in address ) return false; //check for a valid domain at end of address for( var i = 0; i < validDomainArray.length; i++ ) if( validDomainArray[i] == domain ) return true; alert('Please provide a valid email address to begin.'); return false; //invalid address if processing gets here } function validate_checkEmail(email) { // code from: http://webreference.com/js/column5/workaround.html if (window.RegExp) { var invalidPattern = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)"; var validPattern = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; var reg1 = new RegExp(invalidPattern); var reg2 = new RegExp(validPattern); //if email does not match the invalid pattern and does match the valid pattern then return true if (!reg1.test(email) && reg2.test(email)) return true; alert('Please provide a valid email address to begin.'); return false; } //browser doesn't support RegExp object so call simple email validation script return validate_simpleCheckEmail(email); } function verify_demo(form) { if ( form.first_name && form.first_name.value.length < 2 ) { alert("Please provide a first name."); form.first_name.focus(); return false; } if ( form.first_name && form.first_name.value.length > 30 ) { alert("Please provide a first name under 30 characters."); form.first_name.focus(); return false; } if ( form.first_name && /[^A-Za-z\'\-\ ]/.test(form.first_name.value) ){ alert("First name can only contain alpha characters, hyphens, apostrophes or spaces."); form.first_name.focus(); return false; } if ( form.last_name && form.last_name.value.length < 2 ) { alert("Please provide a last name."); form.last_name.focus(); return false; } if ( form.last_name && form.last_name.value.length > 30 ) { alert("Please provide a last name under 30 characters."); form.last_name.focus(); return false; } if ( form.last_name && /[^A-Za-z\'\-\ ]/.test(form.last_name.value) ){ alert("Last name can only contain alpha characters, hyphens, apostrophes or spaces."); form.last_name.focus(); return false; } if ( form.email && !form.email.value.length ) { alert("Please enter your email address"); form.email.focus(); return false; } if ( form.email && !validate_checkEmail(form.email.value) ) { form.email.focus(); return false; } if ( form.address && form.address.value.length < 5 ) { alert("Please provide an address."); form.address.focus(); return false; } if ( form.address && form.address.value.length > 40 ) { alert("Address must be less than 40 characters."); form.address.focus(); return false; } if ( form.city && form.city.value.length < 2 ) { alert("Please provide a city."); form.city.focus(); return false; } if ( form.city && form.city.value.length > 50 ) { alert("City must be less than 50 characters.."); form.city.focus(); return false; } if ( form.state && form.state.options && form.state.options[0].selected == true ) { alert("Please choose a state."); form.state.focus(); return false; } if ( form.zip && !form.zip.value.length ) { alert("Please provide a postal code."); form.zip.focus(); return false; } if ( form.zip && (form.zip.value.length < 5 || isNaN(form.zip.value)) ) { alert("Please provide a valid 5 digit US zip code.\n\nAt this time, MemoLink does not accept registrations outside of the US."); form.zip.focus(); return false; } if ( form.password && !form.password.value.length ) { alert("Please create a password."); form.password.focus(); return false; } if ( form.password2 && ( !form.password2.value.length || form.password.value != form.password2.value ) ) { alert("Your password and confirm password values do not match."); form.password2.focus(); return false; } if ( form.phone_areacode && (form.phone_areacode.value.length || form.phone_exchange.value.length || form.phone_last4digits.value.length) ) { if (isNaN(form.phone_areacode.value) || isNaN(form.phone_exchange.value) || isNaN(form.phone_last4digits.value) ){ alert("phone number must contain only 0-9."); form.phone_areacode.focus(); return false; } if (form.phone_areacode.value.length < 3 || form.phone_exchange.value.length < 3 || form.phone_last4digits.value.length < 4) { alert("Phone number is incomplete"); form.phone_areacode.focus(); return false; } } if ( form.birth_month ) { if (form.birth_year.options[form.birth_year.selectedIndex].value == 0 || form.birth_month.options[form.birth_month.selectedIndex].value == 0 || form.birth_day.options[form.birth_day.selectedIndex].value == 0) { alert('Please provide your birthday.'); form.birth_month.focus(); return false; } if (form.birth_year.options[form.birth_year.selectedIndex].value >= 1990) { if ( form.birth_month.options[form.birth_month.selectedIndex].value > 5 ) { alert("You must be 18 years or older to participate.\n\nPlease review our Terms and Conditions for full details on MustHaveFreeGifts\' membership policy."); form.birth_month.focus(); return false; } if ( form.birth_month.options[form.birth_month.selectedIndex].value == 5 ) if ( form.birth_day.options[form.birth_day.selectedIndex].value > 13) { alert("You must be 18 years or older to participate.\n\nPlease review our Terms and Conditions for full details on MustHaveFreeGifts\' membership policy."); form.birth_month.focus(); return false; } } var dateExists = checkDate(form, 'birth'); if (!dateExists) { alert('You have entered an invalid date'); form.birth_month.focus(); return false; } } form.submit(); return true; }