use Respect\Validation\Validator as v; $email = "john.doe@example.com"; if (!v::email()->validate($email)) { echo "Invalid Email Address"; }
use Illuminate\Support\Facades\Validator; $data = ['phone' => '555-1234']; $rules = ['phone' => 'starts_with:555-|regex:/^\d{3}-\d{4}$/']; $validator = Validator::make($data, $rules); if ($validator->fails()) { echo "Invalid Phone Number"; }
use Symfony\Component\Validator\Validation; use Symfony\Component\Validator\Constraints as Assert; $password = "Abc1234#"; $validator = Validation::createValidator(); $errors = $validator->validate($password, [ new Assert\NotBlank(), new Assert\Length(['min' => 8]), new Assert\Regex(['pattern' => '/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*\W).+$/']), ]); if (count($errors) > 0) { echo "Invalid Password"; }In this example, we have used the Symfony Validation package to check if the given password is not blank, at least 8 characters long, and includes at least one uppercase letter, lowercase letter, digit, and special character. In conclusion, different PHP validation packages or libraries can be used for different types of validations. It is important to choose the appropriate package based on the specific validation requirements.