What are the advantages and disadvantages of using a Pear class for email validation in PHP compared to writing custom validation code?

Using a Pear class for email validation in PHP can save time and effort as it provides a pre-built solution that is well-tested and widely used. However, relying on an external library like Pear may introduce dependencies and potential compatibility issues with future PHP versions. Writing custom validation code gives more control over the validation process and can be tailored to specific requirements, but it requires more time and effort to implement and maintain.

// Using Pear class for email validation
require_once "Mail.php";
$email = "test@example.com";
if (!Mail::validateAddress($email)) {
    echo "Invalid email address";
} else {
    echo "Valid email address";
}

// Custom email validation code
$email = "test@example.com";
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Invalid email address";
} else {
    echo "Valid email address";
}