Created
October 7, 2024 22:07
-
-
Save UltraInstinct0x/4a0592d5604ebed90423c7b010ef95d6 to your computer and use it in GitHub Desktop.
Gmail normalization to prevent free tier abuse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function normalizeGmailAddress(email) { | |
| // Convert to lowercase | |
| email = email.toLowerCase(); | |
| // Split the email into local part and domain | |
| let [localPart, domain] = email.split('@'); | |
| // If it's not a Gmail address, return the original email | |
| if (domain !== 'gmail.com' && domain !== 'googlemail.com') { | |
| return email; | |
| } | |
| // Remove all dots from the local part | |
| localPart = localPart.replace(/\./g, ''); | |
| // Remove everything after '+' in the local part | |
| localPart = localPart.split('+')[0]; | |
| // Normalize googlemail.com to gmail.com | |
| domain = 'gmail.com'; | |
| // Reconstruct the normalized email | |
| return `${localPart}@${domain}`; | |
| } | |
| // Example usage: | |
| const emails = [ | |
| 'example@gmail.com', | |
| 'e.x.a.m.p.l.e@gmail.com', | |
| 'example+1@gmail.com', | |
| 'examp.l.e@googlemail.com', | |
| 'e.xample+2@gmail.com' | |
| ]; | |
| emails.forEach(email => { | |
| console.log(`Original: ${email}`); | |
| console.log(`Normalized: ${normalizeGmailAddress(email)}`); | |
| console.log('---'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment