NiteShift Posted December 6, 2006 Share Posted December 6, 2006 Hi guys/gals,My name is Lee from Manchester, England I'm very new to this PHP malarkey so please go gentle!!I have to do a website in PHP for Uni yet have no experience of using it and very little time to learn it!! I am trying to simply validate an e-mail address but having real problems sorting it out. I have compiled the following pages to test the code yet for the life of me can't get them talking to one another to validate the e-mail:[b]Form1[/b]<html><head></head><body><form action="validate.php" method="post">Enter name: <input type="text" name="fname"><br>Enter e-mail address: <input type="text" name="email"><br><input type=submit name="submit" value="Insert Record"></body></html>[b]Validate.php[/b]<?php$fname=$_POST[fname];$email=$_POST[email];// email addr valid structure check - Welling & Thompson p483 if (!valid_email($email)) { exit;}The function detail below is a 'required':// 2 Welling & Thomson Ch24: check email address is in valid format function valid_email($email) { if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $email)) {return true;} else { print "<h4>Sorry $_POST[fname] - there was a problem with the form details<br /><br /></h4>"; print '<p class="warning">The email address is invalid or blank</p>'; print '<p>Please click the <b>Back</b> button to amend it</p>'; return false; }?>Does anyone have any ideas???Kind regards,Lee Quote Link to comment Share on other sites More sharing options...
Orio Posted December 6, 2006 Share Posted December 6, 2006 This regular expression works great for me :)[code]^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$[/code]In your case it should be:[code]if (ereg('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', $email)) return true;[/code]Orio. Quote Link to comment Share on other sites More sharing options...
NiteShift Posted December 6, 2006 Author Share Posted December 6, 2006 Thanks for that, still not working though! I'm getting the dreaded white screen when validate.php loads. I feel that it is something quite simple but I'm damned if i can see it ;D Quote Link to comment Share on other sites More sharing options...
NiteShift Posted December 6, 2006 Author Share Posted December 6, 2006 Anyone??? Quote Link to comment Share on other sites More sharing options...
marcus Posted December 6, 2006 Share Posted December 6, 2006 Try placing the [code]if (!valid_email($email)) { exit;}[/code]after you define the function Quote Link to comment Share on other sites More sharing options...
NiteShift Posted December 6, 2006 Author Share Posted December 6, 2006 Do I post that here??[code]<?php$fname=$_POST[fname];$email=$_POST[email];// email addr valid structure check - Welling & Thompson p483 if (!valid_email($email)) { exit;}The function detail below is a 'required':// 2 Welling & Thomson Ch24: check email address is in valid format function valid_email($email) { if (ereg('^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $email)) {return true;} else {if (!valid_email($email)) { exit;} print "<h4>Sorry $_POST[fname] - there was a problem with the form details</h4>"; print '<p class="warning">The email address is invalid or blank</p>'; print '<p>Please click the Back button to amend it</p>'; return false; }?>[/code] Quote Link to comment Share on other sites More sharing options...
NiteShift Posted December 10, 2006 Author Share Posted December 10, 2006 Still not working any other ideas???Thanks Quote Link to comment 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.