jamo1616 Posted January 12, 2009 Share Posted January 12, 2009 Excuse my ignorance, I am brand new, and very much a novice when it comes to PHP... I have looked throughout this forum, and could not find a simple answer to this: I have a PHP script that is intended to validate an email address that one enters on a form that is dynamically generated. The script i am trying to implement is: function isValidEmail($email){return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email); } And my form code is: <form name="frm" action="dist.php" method="post" tmt:validate="true" onSubmit="validate()"> <input type="hidden" name="prod_id" value="<?php echo $_GET['find_id'];?>"> <input type="hidden" name="market" value="<?php echo $find['market']; ?>"> <TABLE height=107 cellSpacing=0 cellPadding=0 width=322 align=left border=0> <TR> <TH scope=row height=107> <DIV align=left> <p> <p class="header">Please fill out the following basic information so that we may send you to the appropriate distributor:</p> <table width="100%" border="0"> <tr> <td width="41%"><span class="littleheader">First Name</span><br> <span class="specialheader"> <input name="fname" type="text" id="fname" size="20" tmt:required="false" tmt:message="Please Enter First Name"> </span></td> <td width="59%"><span class="littleheader">Last Name</span><br> <span class="specialheader"> <input name="lname" type="text" id="lname" size="28" tmt:required="false" tmt:message="Plese Enter Last Name"> </span></td> </tr> <tr> <td colspan="2"><p class="littleheader">* Company Name<br> <input name="company" type="text" id="company" size="53" tmt:required="true" tmt:message="Please Enter Company Name"> </p></td> </tr> <tr> <td colspan="2"><p class="littleheader">* Email<br> <input name="email" type="text" id="email" size="53" tmt:required="true" tmt:message="Please Enter Email"> </p></td> </tr> <tr> <td colspan="2"><span class="littleheader">* Zip Code<br> <input type="text" name="zipcode" tmt:required="true" tmt:message="Please Enter Zipcode"> </span></td> </tr> <tr> <td colspan="2"><p class=body><span class=specialheader><br> </span><span class="header">Please Select Your Market(s):</span><span class=specialheader><br> </span></p> <p class=body>*note: you may select more than one<br> <br> </p> <?php $markets=$find['market']; $query_market=executeQuery("select * from tbl_market"); while ($market=mysql_fetch_array($query_market)){?> <input type="checkbox" name="market[]" value="<?php echo $market['id'];?>"> <label class=bodybold1 for=CATV><?php echo strtoupper($market['name']);?></label> <br> <?php } ?> <p></p></td> </tr> <tr> <td colspan="2"><span class="littleheader">Within <br> <select name="miles" class="body"> <option value="5"> 5 miles</option> <option value="10"> 10 miles</option> <option value="15"> 15 miles</option> <option value="20"> 20 miles</option> <option value="25"> 25 miles</option> </select> </span></td> </tr> </table> <P class=littleheader> </P> <input type="hidden" name="product" tmt:required="false" value="<?php echo $_REQUEST['find_id'] ?>"> <input type="image" src="images/find_button.gif" height=20 alt="" width=114 border=0> </div> </TH></TR> </TABLE> </form> -------------------------- I am not sure where to put the script to make sure it validates the email. i have tried it in several locations in the form code, and it has not worked yet. I am not sure if the script is bad, or i am just not putting it in the right place. It is supposed to disallow the user to proceed if the email is bad. As of now, andyone can just put anything in there, and still proceed to the onSubmit page. Any help is greatly appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/140554-simple-email-validator/ Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 please use code tags, it is harder to read without Quote Link to comment https://forums.phpfreaks.com/topic/140554-simple-email-validator/#findComment-735510 Share on other sites More sharing options...
jamo1616 Posted January 12, 2009 Author Share Posted January 12, 2009 Got it... sorry about that The script i am trying to implement is: function isValidEmail($email){return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email); } And my form code is: <form name="frm" action="dist.php" method="post" tmt:validate="true" onSubmit="validate()"> <input type="hidden" name="prod_id" value="<?php echo $_GET['find_id'];?>"> <input type="hidden" name="market" value="<?php echo $find['market']; ?>"> <TABLE height=107 cellSpacing=0 cellPadding=0 width=322 align=left border=0> <TR> <TH scope=row height=107> <DIV align=left> <p> <p class="header">Please fill out the following basic information so that we may send you to the appropriate distributor:</p> <table width="100%" border="0"> <tr> <td width="41%"><span class="littleheader">First Name</span><br> <span class="specialheader"> <input name="fname" type="text" id="fname" size="20" tmt:required="false" tmt:message="Please Enter First Name"> </span></td> <td width="59%"><span class="littleheader">Last Name</span><br> <span class="specialheader"> <input name="lname" type="text" id="lname" size="28" tmt:required="false" tmt:message="Plese Enter Last Name"> </span></td> </tr> <tr> <td colspan="2"><p class="littleheader">* Company Name<br> <input name="company" type="text" id="company" size="53" tmt:required="true" tmt:message="Please Enter Company Name"> </p></td> </tr> <tr> <td colspan="2"><p class="littleheader">* Email<br> <input name="email" type="text" id="email" size="53" tmt:required="true" tmt:message="Please Enter Email"> </p></td> </tr> <tr> <td colspan="2"><span class="littleheader">* Zip Code<br> <input type="text" name="zipcode" tmt:required="true" tmt:message="Please Enter Zipcode"> </span></td> </tr> <tr> <td colspan="2"><p class=body><span class=specialheader><br> </span><span class="header">Please Select Your Market(s):</span><span class=specialheader><br> </span></p> <p class=body>*note: you may select more than one<br> <br> </p> <?php $markets=$find['market']; $query_market=executeQuery("select * from tbl_market"); while ($market=mysql_fetch_array($query_market)){?> <input type="checkbox" name="market[]" value="<?php echo $market['id'];?>"> <label class=bodybold1 for=CATV><?php echo strtoupper($market['name']);?></label> <br> <?php } ?> <p></p></td> </tr> <tr> <td colspan="2"><span class="littleheader">Within <br> <select name="miles" class="body"> <option value="5"> 5 miles</option> <option value="10"> 10 miles</option> <option value="15"> 15 miles</option> <option value="20"> 20 miles</option> <option value="25"> 25 miles</option> </select> </span></td> </tr> </table> <P class=littleheader> </P> <input type="hidden" name="product" tmt:required="false" value="<?php echo $_REQUEST['find_id'] ?>"> <input type="image" src="images/find_button.gif" height=20 alt="" width=114 border=0> </div> </TH></TR> </TABLE> </form> -------------------------- I am not sure where to put the script to make sure it validates the email. i have tried it in several locations in the form code, and it has not worked yet. I am not sure if the script is bad, or i am just not putting it in the right place. It is supposed to disallow the user to proceed if the email is bad. As of now, andyone can just put anything in there, and still proceed to the onSubmit page. Any help is greatly appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/140554-simple-email-validator/#findComment-735513 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 Hmm, you have a lot of code and without any errors it is hard to know what is wrong. Put at the top of the page <?php error_reporting(E_ALL); ini_set("display_errors",true); ?> And maybe have a look at this http://www.plus2net.com/php_tutorial/php_email_validation.php Edit: Where are you calling the function? Quote Link to comment https://forums.phpfreaks.com/topic/140554-simple-email-validator/#findComment-735523 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.