Validation using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tiresome
Forum Newbie
Posts: 16
Joined: Sun Apr 18, 2004 9:45 am

Validation using PHP

Post by tiresome »

I am doing a guest book using PHP and MySql. I am using apache to run all my php codings. I was wondering if anyone of you had any idea as to how to validate an email field in PHP. I want to check if the user has input an email in the format XXX@XXX.XXX.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

I personally use this:

Code: Select all

function email_check($email){
      $check = ereg("^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", $email);
      return $check;
   }
Im sure there has been a few other good ones posted in the code snippet section of this website recently as well.
tiresome
Forum Newbie
Posts: 16
Joined: Sun Apr 18, 2004 9:45 am

Post by tiresome »

Wow! That was quick. Thanks a lot for that. Oh, any idea as to what the difference between cgi and module versions of PHP is? I tried to password protect my PHP page by using Header("WWW-Authenticate: Basic realm=\""); Header("HTTP/1.0 401 Unauthorized"); and I get this pop up dialogue box requesting for the username and password. I created a table in MySql and inserted the username and password in there. That is from where the user input(ie the username/password) would be verified but even when I input the correct username and password I am still unable to log in. Could this be because I am using the cgi version of PHP instead of the module version or am I confusing everyone here? Sorry, for the long winded way of going about this :?
Post Reply