Validation using PHP
Moderator: General Moderators
Validation using PHP
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
I personally use this:
Im sure there has been a few other good ones posted in the code snippet section of this website recently as well.
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;
}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 