View Full Version : What do i need to add... something small
oo7ml
Jun 19th 2007, 3:58 pm
My email validation is as follows
apos=value.indexOf("@")
dotpos=value.lastIndexOf(".")
if (apos<1||dotpos-apos<2)
{alert(alerttxt);return false}
else {return true}
but if i enter an address as example@mydomain. it accepts it because there is nothing to say that there has to be something after the .
Do you know how to ammend this, or so you have a better script than this, thanks
nanolab
Jun 21st 2007, 12:13 pm
You need to compare length of email string and dotpos
krakjoe
Jun 21st 2007, 12:37 pm
IMO regex is the way to go ..... my pattern might be a bit flaky, if you find some email it gives unexpected results on do tell......
<!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 language="javascript">
function checkEmail( address )
{
if( !address.match( /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/ ) )
{
document.getElementById( 'theMessage' ).innerHTML = '<font color=red>Email address is <b>NOT</b> valid</font>';
}
else
{
document.getElementById( 'theMessage' ).innerHTML = '<font color=blue>Email address is valid</font>';
}
}
</script>
</head>
<body>
<div id="theMessage"></div>
<form action="" method="post" name="theForm">
<input type="text" name="email" />
<input type="button" onclick="return checkEmail( document.theForm.email.value )" value="Check Email"/>
</form>
</body>
</html>
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.