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
Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.