For long time we were using regular expression for e-mail validation in php. Since everyone is not so good with these reg exp, the introduction of filter in PHP 5 will be a relief.
There is an option for sanitation in new PHP version. But I dont know, up to what extend this is good in email validation. Email Sanitation helps you to remove some special characters from the given address. Also there are some more sanitation like URL, Numbers etc.
But I think Validation is a better solution than sanitation. Validation for integer, IP etc are also included in this section.
The details are there in the following link.
sanitation and validation
and
http://www.phpro.org/tutorials/Filtering-Data-with-PHP.html#12
I recommend you to use validation too, even if you use the sanitation. The validation is good enough to check @,.(dot). Also it checks for the special characters in local part and domain part differently. Those special characters allowed in local part is not allowed in domain part.
The usage is so simple and easy to understand, since they are inbuilt functions.
Both Sanitation and validation came under PHP Filter.
An example:
<?php
$email = "some{one@exam{ple.com";
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
echo "E-mail is not valid";
}
else
{
echo "E-mail is valid";
}
?>
There is an option for sanitation in new PHP version. But I dont know, up to what extend this is good in email validation. Email Sanitation helps you to remove some special characters from the given address. Also there are some more sanitation like URL, Numbers etc.
But I think Validation is a better solution than sanitation. Validation for integer, IP etc are also included in this section.
The details are there in the following link.
sanitation and validation
and
http://www.phpro.org/tutorials/Filtering-Data-with-PHP.html#12
I recommend you to use validation too, even if you use the sanitation. The validation is good enough to check @,.(dot). Also it checks for the special characters in local part and domain part differently. Those special characters allowed in local part is not allowed in domain part.
The usage is so simple and easy to understand, since they are inbuilt functions.
Both Sanitation and validation came under PHP Filter.
An example:
<?php
$email = "some{one@exam{ple.com";
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
echo "E-mail is not valid";
}
else
{
echo "E-mail is valid";
}
?>