Source Code:
(back to article)
Submit
Result:
Report an issue
<div> <pre> <input type="email" id="emailInput" placeholder="Enter Your Email"> <script> document.getElementById('emailInput').addEventListener('blur', function(event) { const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailRegex.test(event.target.value)) { alert('Please enter a valid email address.'); event.target.style.backgroundColor = 'salmon'; } else { event.target.style.backgroundColor = 'lightgreen'; } }); </script> </pre> </div>