5
Contributors
5
Replies
8
Views
7 Years
Discussion Span
Last Post by muralikalpana
0
function validate_email($email)
{
    if (strlen($email) < 3) {
        return false;
    }
    if (!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/',
        $email)) {
        return false;
    } else {
        return $email;
    }
}
0
function validate_email($email)
{
    if (strlen($email) < 3) {
        return false;
    }
    if (!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/',$email)) {
        return false;
    } else {
        return $email;
    }
}

This code is close, but does not allow addresses ending in .museum or .travel.

That's because the code limits the TLD to have between 2 and 4 characters. I would suggest relaxing the rules a little and not impose an upper limit (i.e. only a minimum of 2 characters). Thus line 6 ought to be:

if (!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,})$/',$email)) {

Edited by edwinhermann: n/a

0

This code is close, but does not allow addresses ending in .museum or .travel.

That's because the code limits the TLD to have between 2 and 4 characters. I would suggest relaxing the rules a little and not impose an upper limit (i.e. only a minimum of 2 characters). Thus line 6 ought to be:

if (!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,})$/',$email)) {

Good point, forgot about those tlds

0

try below code

<script language="javascript">
function functionname()
{
 var emailFormat = /^\w(\.?[\w-])*@\w(\.?[\w-])*\.[a-zA-Z]{2,6}(\.[a-zA-Z]{2})?$/i;
var email=document.formname.emailfieldname.value;
if(email=="")
	{
	alert("Please Enter The Email Id");
	document.formname.emailfieldname.focus();
	return false;
	}
if(email!= "")
		{	
		 	var eres=email.search(emailFormat);
			if(eres == -1)
			{
				alert("Please Enter Valid Email Id ");
				window.document.formname.emailfieldname.focus();
				return false;
			}
		} 
else
{
return true;
}
}

Edited by rajabhaskar525: n/a

-1

Hi friends


I have a site made in PHP
Can someone please help with Email address validation?


Thanks

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">



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>


</head>

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

</form>
</body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.