Hello all,

I'm stuck in a serious problem, I need a code of Email validator in php. It will check whether there is a real email address or not, i.e it should not be "abcd@xyz.com" that means it will check the domain(yahoo.com, gmail.com, aol.com etc..) as well as the user id.....

PLZzzzzzzzzzzzzz help me it's realy very urgent.............

plzzzzzzzzzzz reply..................

Recommended Answers

All 6 Replies

this is the code:

var m = document.form1.emailid.value
	var cnt=0,spc=0,dot=0;
	for(var i=1;i<=m.length;i++)
	{
		if(m.charAt(i)=="@") cnt++;
		if(m.charAt(i)==" ") spc++;
		if(m.charAt(i)==".") dot++;
	}
	lnm=m.length
	if(cnt==0||cnt>1||spc!=0||dot==0 ||lnm<=2 )	{alert("Please Enter Valid E-mail Id ");document.form1.emailid.focus();return false;	}

I've done this way but its not working....

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript">
var m = document.form1.emailid.value
    var cnt=0,spc=0,dot=0;
    for(var i=1;i<=m.length;i++)
    {
        if(m.charAt(i)=="@") cnt++;
        if(m.charAt(i)==" ") spc++;
        if(m.charAt(i)==".") dot++;
    }
    lnm=m.length
    if(cnt==0||cnt>1||spc!=0||dot==0 ||lnm<=2 )  {
    alert("Please Enter Valid E-mail Id ");
    document.form1.emailid.focus();
    return false;   
    }
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="Level1_Verdana.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form name="form1" action="<?php $PHP_SELF;?>" method="post">
  <label>Emaiil : 
  <input name="emailid" type="text" id="emailid" />
  </label>
  <input type="submit" name="enter" value="Enter" />

</form>
</body>
</html>

i changed your code...
its corectly working now:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript">
function check()
{
var m = document.form1.emailid.value
var cnt=0,spc=0,dot=0;
for(var i=1;i<=m.length;i++)
{
if(m.charAt(i)=="@") cnt++;
if(m.charAt(i)==" ") spc++;
if(m.charAt(i)==".") dot++;
}
lnm=m.length
if(cnt==0||cnt>1||spc!=0||dot==0 ||lnm<=2 ) {
alert("Please Enter Valid E-mail Id ");
document.form1.emailid.focus();
return false;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="Level1_Verdana.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form name="form1" action="" method="post" onsubmit="return check()">
<label>Emaiil :
<input name="emailid" type="text" id="emailid" />
</label>
<input type="submit" name="enter" value="Enter" />

</form>
</body>
</html>

error was:
you didnt cal any function in your form tag...

hai u can use this validation code it will accept mail id in the form of aa@aa.aa<body>
<script type="text/javascript">

/***********************************************
* Email Validation script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Please enter a valid email address.")
e.select()
}
return returnval
}

</script>

<form>
<input name="myemail" type="text" style="width: 270px"> <input type="submit" onClick="return checkmail(this.form.myemail)" value="Submit" />

</form>

</body>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.