Jump to content

Email verification


Nic727

Recommended Posts

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

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 by Nic727
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...