<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
document.addEventListener('DOMContentLoaded', () => {
const input = document.querySelector('input');
const p = document.querySelector('p');
const isEmail = (value) => {
return(value.indexOf('@') > 1) && (value.split('@')[1].indexOf('.') > 1);
}
input.addEventListener('keyup', (event) => {
const value = input.value;
if (isEmail(value)) {
p.style.color = 'green'
p.textContent = `이메일 형식입니다: ${value}`;
}
else {
p.style.color = 'red'
p.textContent = `이메일 형식이 아닙니다: ${value}`;
}
})
});
</script>
<input type="text">
<p></p>
</body>
</html>