Create a new document called l5p3.html. It should have a form with a text input
ID: 3678522 • Letter: C
Question
Create a new document called l5p3.html. It should have a form with a text input box for an email address and a Submit button. Submitting the form (either by clicking the button or pressing enter when the button has focus) should call a function that validates the email address. The function should use a regular expression to validate the email address and return true if valid, or use alert() to display an error message and return false if not. If the function returns false, the form should not be submitted. Otherwise, submit the form to http://weblab.kennesaw.edu/formtest.php. Your regular expression should test for exactly this:
One or more word characters
Exactly one at-sign
One or more word characters
Exactly one period
Two or more characters that are a-z, A-Z, 0-9, period, or hyphen
Explanation / Answer
<!--
The regular expression that i have entered validates any email.
-->
<!DOCTYPE html>
<html>
<head>
<script>
function Validmail()
{
var email=document.getElementById("mailer").value;
var re = /^(([^<>()[]\.,;:s@"]+(.[^<>()[]\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/;
if(!re.test(email))
alert("Enter valid mail");
return re.test(email);
}
</script>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="http://weblab.kennesaw.edu/formtest.php" method="post">
<input id="mailer" type="text">
<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.