Login Form Change Colors
Go to solution
Solved by leodaniel,
Use Javascript to make a request and check the email...
I would consider this as not best practice, because an attaquer can verify if the email is valid... I would always only return that the combination of email and password didn't match
/* Remove Success and error classes */ document.getElementById('email').classList.remove('error','success'); /* I will use the Axios Library */ axios.post('/verify_email',{ email:'from the input' }) .then(function (response) { //console.log(response); //Server Responded with an HTTP Status 200 // Add a Class to the element document.getElementById('email').classList.add('success'); }) .catch(function (error) { // console.log(error); document.getElementById('email').classList.add('error'); });
If it's just about validating the email format, I think this regex will cover you needs... I used it in an older project, I m not up to date if it covers the email format requirements up to 100%... but it should be fine
function validateEmail(email){ let regex = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/; return regex.test(email); } document.getElementById('email').addEventListener('change',function(e){ /* Reset */ e.target.classList.remove('error','success'); if(validateEmail(e.target.value)){ e.target.classList.add('success'); } else{ e.target.classList.add('error'); } });
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now