Skip to content

Commit

Permalink
Added trusted email validation to signup form
Browse files Browse the repository at this point in the history
  • Loading branch information
ygowthamr committed Nov 8, 2024
1 parent 30a93e3 commit 039930c
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions user_signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,15 @@
<div class="w-96 ml-auto flex flex-col gap-8">
<h1 class="text-3xl font-bold">Hello, Good to see you</h1>

<form action="user_signup.php" method="post" class="flex flex-col gap-4">
<form action="user_signup.php" method="post" onsubmit="return validateEmail()" class="flex flex-col gap-4">
<div class="form-group">
<label for="name" class="mb-2">Name</label>
<input type="text" id="name" name="name" placeholder="Enter your name" class="p-2 border border-black" required>
</div>
<div class="form-group">
<label for="email" class="mb-2">Email</label>
<input type="email" id="email-id" name="email" placeholder="[email protected]" class="p-2 border border-black" required>
<input type="email" id="email-id" name="email" placeholder="[email protected]" class="p-2 border border-black" required><br>
<span id="email-error" class="text-red-500 text-sm hidden">Please enter a trusted email address.</span>
</div>
<div class="form-group">
<label for="password" class="mb-2">Password</label>
Expand Down Expand Up @@ -185,6 +186,51 @@ class="flex items-center justify-center w-full p-2 border border-gray-300 rounde
</body>

<script>

function validateEmail() {
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',
'countermail.com',
'hushmail.com',
'inbox.com',
'mail.ru',
'rediffmail.com',
'seznam.cz'
];

const email = document.getElementById("email-id").value;

console.log(email+"email");

if (!trustedDomains.includes(email)) {
document.getElementById("email-error").classList.remove("hidden");
return false;
}

return true;
}

const eyeBtnPassword =document.getElementById("eye-btn-p");
const eyeBtnConfirmPassword =document.getElementById("eye-btn-cp");
const passwordField =document.getElementById("password");
Expand Down

0 comments on commit 039930c

Please sign in to comment.