Well I need a quick solution for checking if a string contains an email address or anything of the similar, example:
I allow user to type in their personal profile in a textarea and name it "profile"
so in php i will catch it in $profile but would want to check if there is an email value in it. If there is, an error will be trigered as this is not allowed.
Please help.
Thanks
Basher you want to use 'regular expressions'. Do a Google for recipe cut and paste scripts. Regular expressions in short are characters used - in this case - to constrain your data input to form. In other words, if a user does not input an email address as
something@someplace.ext they will get the }else{ error you code.
Here is an example:
I am using the eregi() function as !eregi and the eregi_replace. What this does is first determines if the input is a formated email address. If not, the error. If so, it recodifies it as a link. YOU can adjust it of course. Learn more about Regular Expressions!
-
-
//Check the mail address
-
-
if (!eregi ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$',
-
stripslashes(trim($_POST['email'])))) {
-
$problem = TRUE;
-
$message .= '<p class="error">Please enter a valid email address.</p>';
-
-
} else {
-
-
$email = eregi_replace ('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', '<a href="mailto:\\0">Email</a>',
-
stripslashes(trim($_POST['email'])));
-
-
}
-
-
-
-
Marc