<HTML> <!-- ARCHIVE by FORTUNECITY.ws --> <HEAD> <TITLE>Age & Email Validator (Suzanne Stagel's JavaScript Assignment #4 Part I) </TITLE> <SCRIPT language="JavaScript"> <!-- //Begin hiding JavaScript code from non-enabled browsers //This script does not use any form validation library. All validation of form entries is //done in this script. See other version for example of use of library functions. var ageValid = false; //indicates if age entry is valid var emailValid = false; //indicates if email entry is valid // validateAge // Parameters: age, minimumAge // Functionality: verifies that the age is greater than or equal to the minimumAge function validateAge(age,minimumAge) { if (age < minimumAge) { alert("You indicated you are " + age + " years old. " + "You must be " + minimumAge + " to use this site. Please visit us after you turn " + minimumAge + "."); ageValid = false; } else { ageValid = true; } } // validateEmail // Parameters: emailString // Functionality: verifies that the emailString is properly formed // (with "@" and "." in correct relative positions) function validateEmail(emailString) { var atCharacter = "@"; var dotCharacter = "."; var emailLength = emailString.length; var atPosition = -1; var dotPosition = -1; //Check that email address contains "@" symbol and not as first character atPosition = emailString.search(atCharacter); if (atPosition == -1 || atPosition == 0) { alert("The email address you entered is invalid. Please reenter."); emailValid = false; } else {//search for "." symbol dotPosition = -1; //Find dotCharacter in emailString (-1 if not contained in string) while (dotPosition < emailLength) { if (emailString.charAt(dotPosition) == dotCharacter) { break; } else if (dotPosition == (emailLength-1)) { dotPosition = -1; break; } else dotPosition++; } //end while //Check that email address contains "." (dotCharacter) and is not the character //immediately following the "@" (atCharacter) and is not last character in entry if ( (dotPosition <= 0) || (dotPosition <= (atPosition+1)) || (dotPosition == (emailLength-1)) ) { alert("The email address you entered is invalid. Please reenter."); emailValid = false; } else { emailValid = true; } } } //--> </SCRIPT> </HEAD> <BODY ><script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-47423994-1', 'fortunecity.ws'); ga('send', 'pageview'); </script> <center> <br> <div> <script language="javascript" type="text/javascript" src="http://ad.broadcaststation.net/ads/show_ad.php?width=728&height=90"></script> </div> </center> <center> <br> <div style="height:5px"></div> </center> <FORM name="demographicsForm"> <TABLE cols="100,100" bgcolor="lightyellow" align=center border=1 cellpadding=10> <TR bgcolor="#23238E"> <TD COLSPAN=2 align=center><B><FONT color="white">Please enter your details</FONT></B> </TD> </TR> <TR> <TD width=100><INPUT type="text" value="Name" name="name"></TD> </TR> <TR> <TD><INPUT type="text" value="E-mail Address" name="email" onChange="validateEmail(this.value)"></TD> </TR> <TR> <TD><INPUT type="text" value="Your Age" name="age" onChange="validateAge(this.value,18)"></TD> </TR> </TABLE> </FORM> </BODY> <!-- ARCHIVE by FORTUNECITY.ws --> <center> <div> <br> <script language="javascript" type="text/javascript" src="http://ad.broadcaststation.net/ads/show_ad.php?width=300&height=250&cache=0"></script> <script language="javascript" type="text/javascript" src="http://ad.broadcaststation.net/ads/show_ad.php?width=300&height=250"></script> </div> <br> <br> </center> </HTML>