Nic727 Posted November 25, 2015 Share Posted November 25, 2015 Hi, I'm unable to verify an email in my form. That's the code I found : var filter = /^\w+([\.-]?\w+)*[@]\w+([\.-]?\w+)*(\.\w{2,4})+$/; And now to verify I have that, but it doesn't work at all. if(document.getElementById("Email").value.length<=0 || filter.test(document.getElementById("Email")) ){ document.getElementById("Email").style.border="2px solid #ff0000"; block=false; } So it suppose to verify if the email contain @ and a .com/.info/.net/etc. + characters... In my code : Block=false is when there is an error (field not completed, etc.) At the end of my verification code, I have if(block){ return true; }else{ document.getElementById("error").innerHTML="You didn't complete all required field" document.getElementById("error").style.color="#ff0000"; return false; } I used this tutorial here : http://www.w3resource.com/javascript/form/email-validation.php Also, in the comment he is saying that to verify if the email exist "within a forms's opening tag, you mention action="url", where url is the filename where you want to send your form data." So do you have an easier code or something to help me validate the email address? Thank you Link to comment Share on other sites More sharing options...
thescientist Posted November 25, 2015 Share Posted November 25, 2015 Is email an input element? Either way, you need to be using .value or .innerHTML when you call the test method. Link to comment Share on other sites More sharing options...
Nic727 Posted November 25, 2015 Author Share Posted November 25, 2015 (edited) What do you mean? Also, I added ! before filter.test, but now it give me error even if I enter @blabla.com EDIT : Now it work, I forgot to add .value after my getElementById("email").value But now how can I verify if the email actually exist? (maybe if a code exist for that, it will remove this code?) Edited November 25, 2015 by Nic727 Link to comment Share on other sites More sharing options...
justsomeguy Posted November 25, 2015 Share Posted November 25, 2015 If you want verify whether or not an email address exists then you send an email to it with a link for them to click to validate the email address. Link to comment Share on other sites More sharing options...
Recommended Posts
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