Jump to content

Hello from a newbie and e-mail validation help


NiteShift

Recommended Posts

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
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.
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.