A PHP 8.2+ Attribute Based Valdiation For Properties of Object/Entity/DTO. Comes with in-built data-type converter that can be implmented to make validation easy without compromising your object. You can create your own custom Validators and/or Converter by implmenting a simple interface.
The Validators are PHP attribute that validates object properties:
The Validators are PHP attribute that validates object properties:
Validator | Parameters | Definition | Example |
---|---|---|---|
|
An Validator Abstract class that can be used to implement other validator object. | ||
|
validates if a string contains only alphabetic characters.
|
|
|
AlphaNumeric |
|
validates if a string contains only alphanumeric
characters, hyphens, periods, underscores, commas, at symbols, and spaces.
|
|
|
validator that checks if a value is a valid boolean
|
|
|
|
validates if a string contains at least one lowercase letter
|
|
|
|
checks if the value contains at least one numeric character
|
#[ContainsNumeric]
protected ?string $password; |
|
|
validate if a string contains at least one special character.
|
#[ContainsSpecialCharacter]
protected ?string $password; |
|
|
validates if a string contains at least one uppercase letter.
|
#[ContainsUpperCase]
protected ?string $password; |
|
|
validates if a given value is a valid date.
|
#[DateValidator]
protected ?\DateTime $createdAt; |
|
|
validator that checks if a value is of type double.
|
#[Double]
|
|
|
validator that checks if a given value is a valid email address.
|
#[Email]
|
|
|
validates whether a given value is a valid float.
|
#[FloatValidator]
|
|
|
validator that checks if a given value is present in a specified array.
|
#[InArray('RICE', 'BEANS')]
|
|
|
validates whether a given value is an integer.
|
#[IntegerValidator]
|
|
|
validator that checks if a given value is a valid IP address.
|
#[IpAddress]
|
|
|
validator that checks if a given value is a valid base64 string.
|
#[IsBase64]
|
|
|
validate the length of a property value, with a minimum and maximum length specified.
|
#[Length(1, 10)]
|
|
|
validator that checks if a value is less than or equal to a specified maximum value.
|
#[Max(120)]
|
|
|
validator that checks if a given value’s length exceeds a specified maximum length.
|
#[MaxLength(255)]
|
|
|
validator that checks if a value is greater than or equal to a specified minimum value. | #[Min(18)]
|
|
|
validator that checks if a given value has a minimum length.
|
#[MaxLength(255)]
|
|
|
validator that checks if a given value is not empty or blank.
|
#[NotBlank]
|
|
|
validator that checks if a property is not empty.
|
#[NotEmpty]
|
|
|
validator that checks if a property is not null.
|
#[NotNull]
|
|
|
validate if a given value is numeric
|
#[Numeric]
|
|
|
validates whether a given value meets certain password requirements.
|
#[Password]
|
|
Pattern |
|
validator that checks if a given value matches a
specified regular expression pattern.
|
)]
|
Required |
|
validates that the
value is not empty/null/blank/0
|
#[Required]
|
Size |
|
validator that checks if the length of a value is equal to a specified size.
|
#[Size(120)]
|
StringValidator |
|
validates if a given value is a string. | #[StringValidator]
|
UrlValidator |
|
validates if a given value is a valid URL. | #[UrlValidator]
|