PHP Tutorial : Valid email checking script

Hi,
Do you have any newsletters, contact forms or other pages where you require an email address ? If so, did you ever thought that someone might type “asd”, “452″ and other dummy words instead of a valid email address? Huh, for that I built an email validation script which checks for those things.

<?php
function validMail ($email,$link) {
	if(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z\-\.]+$",$email)) {
		print "Email address appears to be invalid<br />";
		print "Go back <a href=\"$link\" title=\"inapoi\">click aici</a>";
		exit();
	}
}
?>

You will need to pass two arguments :
1) $email field
2) $link to go back if email is invalid
Right like here

<?php
$email = "abcdef";

validMail($email, "complete-form.php");
?>

5 Responses to “PHP Tutorial : Valid email checking script”

  1. Reader Says:

    Great! Thank you very much!
    I always wanted to write in my site something like that. Can I take part of your post to my blog?
    Of course, I will add backlink?

    Sincerely, Timur I. Alhimenkov


  2. admin Says:

    Thanks but
    Nope sorry you cannot take nothing because I want to keep my content fresh and unique to avoid google penalties.


  3. Birmalidand Says:

    Hi. Your site displays incorrectly in Firefox, but content excellent! Thanks for your wise words.


  4. admin Says:

    Great to hear, on me site displays ok in all three tested browser : firefox, ie and opera!


  5. AssowMosyagot Says:

    Hi, cool site, good writing ;)


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>