2021-12-03 14:29:59 +05:30

33 lines
974 B
HTML

<!doctype html>
<html>
<head>
<title>JavaScript Course</title>
</head>
<body>
<div class="output"></div>
<input type="text" placeholder="Enter Email">
<button>Check</button>
<script>
const output = document.querySelector(".output");
const emailVal = document.querySelector("input");
const btn = document.querySelector("button");
const emailExp = /([A-Za-z0-9._-]+@[A-Za-z0-9._-]+\.[A-Za-z0-9]+)\w+/;
btn.addEventListener("click", (e) => {
const val = emailVal.value;
const result = emailExp.test(val);
let response = "";
if (!result) {
response = "Invalid Email";
output.style.color = "red";
} else {
response = "Valid Email";
output.style.color = "green";
}
emailVal.value = "";
output.textContent = response;
});
</script>
</body>
</html>