View Single Post
Old 02-21-2008, 02:16 AM   #1 (permalink)
Gareth
The Acquainted
 
Gareth's Avatar
 
Join Date: Jan 2008
Posts: 136
Thanks: 4
Gareth is on a distinguished road
Default Simple Email Validation

Hey,

This might seem really noobish, but I wanted to create a simple, but effective email validation function.

Most other functions/classes were too complicated: they did things which I did not need and were way above me. My aim was to make sure that the email a user entered basically was an email.

I would love suggestions on how I could improve it, as I am sure there are improvements to be made!

PHP Code:
function checkEmail($email) {
    if(
eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$"$email)) {
        return 
true;
          }else{
        return 
false;
        }

uses as such:

PHP Code:
$email "gwp123@gwp123.com";

    if (
checkEmail($email)){
         echo 
'its valid!';         
     } else {
        echo 
'its not valid :(';
    } 
This would echo out "its valid!".

Gareth

Last edited by Gareth : 02-21-2008 at 01:22 PM.
Gareth is offline  
Reply With Quote