- Forums
- Javascipt
- How To Validate Check Email Address Is Correct In Forms When Submit Php
this is a simple javascript code which you can use to validate your web forms. there are more advance ways to do this like to use jquery validation which is the best way [782], Last Updated: Sat May 18, 2024
webmaster
Tue Dec 19, 2006
5 Comments
10688 Visits
one of the best way to communicate with visitors and user is to provide a form. One of the most popular forms is the contact us forms. One of the essential fields to ask a user is for their email address. However, there are many people who just put garbage and not a real email address and you end up with spam or fake people's email address.
One way to confirm that users put a valid email address is with javascript, in my example if the user does not enter a vallid email address, they will received a popup window telling them that the email address they provided is not correct and to try again.
To teach you how to follow this step by step tutorial guide, start by opening you text editor and copy and paste the following code into your notepad:
CODE:
<HTML>
<TITLE>Javascript Script Tutorial Check Email Address On Forms when submitted</TITLE>
<HEAD>
<script language="JavaScript1.2">
var find_result
function form_email(){
var str=document.validation.email_address.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
find_result=true
else{
alert("ERROR: Please enter a valid Email Address!")
find_result=false
}
return (find_result)
}
</script>
<script>
function checkbae(){
if (document.layers||document.getElementById||document.all)
return form_email()
else
return true
}
</script>
</HEAD>
<style type="text/css">
<!--
.style2 {color: #0066FF}
.style3 {
color: #009933;
font-weight: bold;
}
.style5 {color: #0066FF; font-weight: bold; }
-->
</style>
<BODY>
<strong>Javascript Script Tutorial Check Email Address On Forms when submitted
</strong>
<? if($_POST[submit]){ ?>
<h1 align="center" class="style2">Congratulations: <span class="style3"><?php echo $_POST[email_address]; ?></span> is a valid Email</h1> <? }
else {?>
<br /><br /><br /><br /><form name="validation" onSubmit="return checkbae()" method="post">
<table border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#999999">
<tr>
<td bgcolor="#FFFFFF">Please enter a valid email address:<br></td>
<td bgcolor="#FFFFFF"><input type="text" size=18 name="email_address"></td>
</tr>
<tr align="center">
<td bgcolor="#FFFFFF">(example:
[email protected])</td>
<td bgcolor="#FFFFFF"><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
<?php } ?>
<br />
<span class="style3">NOTE</span>: you must have javascript enabled in your browser for this to work, if you want to know how to enable javascript in your browser, <a href="http://www.wallpaperama.com/forums/show-me-how-to-enable-javascript-in-firefox-browser-t43.html">CLICK HERE </a><br /><br />
<div align="center">Turotial by <a href="http://www.wallpaperama.com">Wallpaperama.com</a></div>
<hr size="2" noshade>
<p>This Script is provided by <span class="style5">Wallpaperama.com</span> - Support us by telling your friends about wallpaperama and help contribut to the open source by adding your knowledge of PHP, Linux, Mysql and more to others, just like this script.</p>
<p>Thank You</p>
<p class="style3">Wallpaperama Team</p>
<p><a href="http://www.wallpaperama.com/forums"><< Go Back</a> </p>
<p align="center">PHP Hosting by <a href="http://www.webune.com">Webune.com</a> </p>
<p>
</BODY>
</HTML>
now save your file to whatever you want, i will be saving it as: javascript-valid-email
upload to your website and open it with your browser to see how it works
Our friends at www.webune.com have provided us with php hosting to show you a demo of how it would look like on your website:
if you own your website, and you have benefited or learned from this simple tutorial, we would like to ask you put our link in your site, or to exchange links with us.
Thank you
Wallpaperama Team