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!
hi all, ive got a form that asks the user to enter certain info and saves it in a table... when a text field is left empty an error will come up using an if statement, but now i would like an error to come up if no '@' is found in the email field....
the code i use for empty fields is..
if($Email == null){
Die (print"Please enter a valid email address");
}
JakeJ wrote:Here's a regular expression that will validate an email address as being legitimate. Adapt to your needs (taking out the echos for example).
<?php
if(isset($todo) and $todo=="test"){
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
echo "<center>Invalid email</center>";
}else{
echo "<center>Valid Email</center>";}
}
?>
eregi() is deprecated, so I would use preg_match(). There is also a built in PHP filter for email. Check filter_var().
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
no that was just a snippet of code line 14 was the 'preg_match'...
but i think it may of had something to do with using php4? i have updated my code so i can now use php5 and it works ok with the built in email verification tool... i have also added the quotes ond semi colons now too, thanks for the help and sujestions