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 Link to comment https://forums.phpfreaks.com/topic/29696-hello-from-a-newbie-and-e-mail-validation-help/ 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. Link to comment https://forums.phpfreaks.com/topic/29696-hello-from-a-newbie-and-e-mail-validation-help/#findComment-136331 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 Link to comment https://forums.phpfreaks.com/topic/29696-hello-from-a-newbie-and-e-mail-validation-help/#findComment-136341 Share on other sites More sharing options...
NiteShift Posted December 6, 2006 Author Share Posted December 6, 2006 Anyone??? Link to comment https://forums.phpfreaks.com/topic/29696-hello-from-a-newbie-and-e-mail-validation-help/#findComment-136395 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 Link to comment https://forums.phpfreaks.com/topic/29696-hello-from-a-newbie-and-e-mail-validation-help/#findComment-136397 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] Link to comment https://forums.phpfreaks.com/topic/29696-hello-from-a-newbie-and-e-mail-validation-help/#findComment-136421 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 Link to comment https://forums.phpfreaks.com/topic/29696-hello-from-a-newbie-and-e-mail-validation-help/#findComment-138428 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.