Based on the code below, develop a webpage with Javascript that will block \"fre
ID: 3572613 • Letter: B
Question
Based on the code below, develop a webpage with Javascript that will block "free/personal" email providers (i.e. Live.com, Me.com, Mail.com) from being registered. When a user enters an incorrect email address (i.e. thomas@live.com) they will be redirected to an error page (embad.html)
<html>
<head>
<script type="text/javascript">
function EmailValUsingJsFct(field, alertMsg)
{
with (field)
{
AtSymbol = value.indexOf("@");
DotSymbol = value.lastIndexOf(".");
if (AtSymbol < 1 || DotSymbol - AtSymbol < 2)
{
alert(alertMsg);
return false;
}
else
{
return true;
}
}
}
function FormValByJsFunction(formid)
{
with (formid)
{
if (EmailValUsingJsFct(email, "The email you entered is incorrect. Try again :)") == false)
{
email.focus();
return false;
}
}
}
</script>
</head>
<body>
<form action="emgood.html" method="post">
Please enter your email: <input type="text" name="email" size="32">
<input type="submit" value="Submit">
</form>
</body>
</html>
Explanation / Answer
<html>
<head>
<script type="text/javascript">
function FormValByJsFunction()
{
var email=document.getElementById("email");
exp1=/[a-z]+@live.com$/;
exp2=/[a-z]+@me.com$/;
exp3=/[a-z]+@mail.com$/;
if(email.value.match(exp1)||email.value.match(exp1)||email.value.match(exp1))
{
alert("please enter right email");
window.location.href = "emBad.html";
return false;
}
return true;
}
</script>
</head>
<body>
<form action="emgood.html" method="post">
Please enter your email: <input type="text" name="email" size="32">
<input type="submit" value="Submit">
</form>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.