SET(A) Q1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript form validation - checking email</title>
<link rel='stylesheet' href='form-style.css' type='text/css' />
</head>
<body bgcolor="cyan">
<h2>ENTER Email ID</h2>
<form>
<input type='text' name='text1'/>
<input type="submit" name="submit" value="Submit" onclick="ValidateEmail(text1)"/>
</form>
<script>
function ValidateEmail(inputText)
{
var mailformat = new RegExp('[a-z0-9]+@[a-z]+.[a-z]{2,3}');
if(inputText.value.match(mailformat))
{
alert("Valid email address!");
document.form1.text1.focus();
return true;
}
else
{
alert("You have entered an invalid email address!");
document.form1.text1.focus();
return false;
}
}
</script>
</body>
</html>
Comments
Post a Comment