For easy unsderstanding study prototype
1.Start designing the form
<html>
<title>Email Validation</title>
<head>
</head>
<body>
<form id="nwires" name='nwires' method="post" action="http://yoursite.com">
<input id="email_lookup" class="signin" type="text" value="Enter email here" title="Enter email here" size="30" name="email_lookup"/>
<input type="submit" value="Send" name="commit"/>
</form>
<script type='text/javascript' src='prototype.js'></script>
<script type='text/javascript' src='validate.js'></script>
</body>
</html>
2.Your external Validate.js should be
/*Function for Email validation */
$('nwires').onsubmit = function()
{
var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
str =$('email_lookup').value;
if(str.match(emailRegEx)){
$('nwires').submit();
}else{
alert('Please enter a valid email address.');
return false;
}
}
No comments :
Post a Comment