use Symfony\Component\Validator\Validation; use Symfony\Component\Validator\Constraints as Assert; $input = "John Smith"; $validator = Validation::createValidator(); $errors = $validator->validate( $input, [ new Assert\NotBlank(), new Assert\Regex(['pattern' => '/^[a-zA-Z\s]*$/']) ] ); if (count($errors) > 0) { // handle validation errors } else { // process input }
use Illuminate\Support\Facades\Validator; $input = 50; $validator = Validator::make( ['input' => $input], ['input' => 'numeric|min:0|max:100'] ); if ($validator->fails()) { // handle validation errors } else { // process input }
use Respect\Validation\Validator as v; $input = "john@example.com"; if (v::email()->validate($input)) { // process input } else { // handle validation errors }In this example, the input is validated using the `email` rule to check if it's a valid email address. Package/library: Respect Validation