Skip to content

Commit

Permalink
Added trusted email validation functionality in feedback page
Browse files Browse the repository at this point in the history
  • Loading branch information
ygowthamr committed Oct 27, 2024
1 parent 644c550 commit 9ee273c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions give_feedback.html
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,44 @@ <h3>Message Sent</h3>
const closePopup = document.getElementById('closePopup');
const feedbackResult = document.getElementById('feedback-result');

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',
'*.ac.uk',
'*.edu.in',
'*.edu.au',
'examplecompany.com',
'mailfence.com',
'posteo.de',
'runbox.com'
];

// Email validation function to check format and domain
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
)
);
}

submitBtn.addEventListener('click', () => {
const name = document.getElementById('Name').value.trim();
const email = document.getElementById('email2').value.trim();
Expand All @@ -579,6 +617,11 @@ <h3>Message Sent</h3>
alert('Please enter a feedback message!');
return; // Stop execution if name is empty
}
if (!validateEmail(email)) {
alert('Please enter a valid email address from a trusted provider.');
return;
}


// Display feedback result in popup
feedbackResult.innerHTML = `Thank you, ${name}!<br>Your feedback: ${message}<br>Rating: ${rating} stars`;
Expand Down

0 comments on commit 9ee273c

Please sign in to comment.