Page 1 of 1

Validation using PHP

Posted: Sun Apr 18, 2004 9:45 am
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.

Posted: Sun Apr 18, 2004 9:47 am
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.

Posted: Sun Apr 18, 2004 10:07 am
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 :?