Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Trusted email validation functionality in news letter form #372

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions public/script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,52 @@ document.addEventListener('DOMContentLoaded', function() {
});

// Handle form submission
const trustedDomains = [
'gmail.com',
'outlook.com',
'yahoo.com',
'protonmail.com',
'icloud.com',
'tutanota.com',
'hotmail.com',
'live.com',
'mail.com',
'zoho.com',
'gmx.com',
'aol.com',
'fastmail.com',
'yandex.com',
'*.edu', // Educational institutions
'*.ac.uk' // UK universities
];

function validateEmail(email) {
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // Basic email format validation
const domain = email.split('@')[1];

return (
emailPattern.test(email) &&
trustedDomains.some((trusted) =>
trusted.includes('*') ? domain.endsWith(trusted.slice(1)) : domain === trusted
)
);
}

document.getElementById('emailForm-nl').addEventListener('submit', function(event) {
event.preventDefault();

const email = document.getElementById('email-nl').value;
const email = document.getElementById('email-nl').value.trim();

// Trusted email validation
if (!validateEmail(email)) {
alert('Please enter a valid email address from a trusted provider.');
return;
}

if (email) {
alert(`Your email ID ${email} has been registered successfully for the newsletter.`);
document.getElementById('popup-nl').style.display = 'none'; // Hide the popup

// Set the subscribed flag in localStorage
localStorage.setItem('subscribed', 'true');
}
Expand All @@ -287,6 +325,4 @@ document.addEventListener('DOMContentLoaded', function() {
event.preventDefault();
document.getElementById('popup-nl').style.display = 'none';
});
});


});