screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <title>Regex Extract Domain from Email in Javascript</title> </head> <body> <h3>Regex Extract Domain from Email in Javascript</h3> <p>Email: <span id="email">Demo@gmail.com</span></p> <p id="result"></p> <button onclick="getDomain()">Get Domain Name From Email</button> <script> function getDomainFromEmail(email) { var regex = /@([^\s@]+)/; var matches = email.match(regex); if (matches && matches.length > 1) { return matches[1]; } return null; } function getDomain() { var emailSpan = document.getElementById('email'); var email = emailSpan.textContent; var resultDiv = document.getElementById('result'); var domain = getDomainFromEmail(email); resultDiv.textContent = domain; } </script> </body> </html>