02-21-2008, 02:16 AM
|
#1 (permalink)
|
|
The Acquainted
Join Date: Jan 2008
Posts: 136
Thanks: 4
|
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.
|
|
|
|