48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			HTML
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			HTML
		
	
	
		
			Executable File
		
	
	
	
	
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 | 
						|
<html>
 | 
						|
<head>
 | 
						|
  <title>Example 4.27</title>
 | 
						|
<script>
 | 
						|
function getEmail()
 | 
						|
{
 | 
						|
	var atSign = "@";
 | 
						|
	email = prompt("Enter your email address", " ");
 | 
						|
	numChars = email.length;
 | 
						|
	okSign = 1;
 | 
						|
	for( j = 1; j < numChars; j++)  //start at 1 because need at least 1 char before @
 | 
						|
	{
 | 
						|
		if (email.charAt(j) == atSign)
 | 
						|
		   {
 | 
						|
		   okSign = 0; 
 | 
						|
		   }
 | 
						|
	}
 | 
						|
	if (okSign == 0)
 | 
						|
	{
 | 
						|
	   if (email.charAt(numChars - 4) != ".")
 | 
						|
	   {
 | 
						|
	   	  document.getElementById("message").innerHTML ="<h3>You entered " + email + ". This is not a valid email address.</h3>";
 | 
						|
		  }
 | 
						|
		else
 | 
						|
		{
 | 
						|
		  document.getElementById("message").innerHTML = "<h3>You entered " + email + ". This is a valid email address.</h3>";
 | 
						|
		  }
 | 
						|
	}
 | 
						|
	else
 | 
						|
		   {
 | 
						|
		   	document.getElementById("message").innerHTML = "<h3>You entered " + email + ". This is not a valid email address.</h3>";
 | 
						|
			}
 | 
						|
}
 | 
						|
</script>
 | 
						|
</<head>
 | 
						|
<body>
 | 
						|
<table align ="center" width ="70%"><tr><td colspan ="2">
 | 
						|
<h1> </h2>
 | 
						|
<h1>Enter your contact information</h1>
 | 
						|
<tr><td><p> </p>
 | 
						|
<p><input type="button" id="email" value="Begin now" onclick="getEmail();" /></p>
 | 
						|
</td></tr>
 | 
						|
<tr><td id ="message"><p> </p></td></tr>
 | 
						|
</table></body>
 | 
						|
</html>
 | 
						|
 |