Phalcon validation
NOTE
All classes are prefixed with Phalcon
Filter\Validation¶
-
Namespace
Phalcon\Filter
-
Uses
Phalcon\Di\Di
Phalcon\Di\DiInterface
Phalcon\Di\Injectable
Phalcon\Filter\FilterInterface
Phalcon\Filter\Validation\AbstractCombinedFieldsValidator
Phalcon\Filter\Validation\Exception
Phalcon\Filter\Validation\ValidationInterface
Phalcon\Filter\Validation\ValidatorInterface
Phalcon\Messages\MessageInterface
Phalcon\Messages\Messages
-
Extends
Injectable
-
Implements
ValidationInterface
Allows to validate data using custom or built-in validators
Properties¶
//
protected $combinedFieldsValidators;
//
protected $data;
//
protected $entity;
//
protected $filters;
//
protected $labels;
//
protected $messages;
//
protected $validators;
//
protected $values;
Methods¶
Phalcon\Validation constructor Adds a validator to a field Appends a message to the messages list Assigns the data to an entity The entity is used to obtain the validation values Returns the bound entity Returns all the filters or a specific one Get label for field Returns the registered validators Returns the validators added to the validation Gets the a value to validate in the array/object data source Alias ofadd
method Adds the validators to a field Sets the bound entity Adds filters to the field Adds labels for fields Validate a set of data according to a set of rules Internal validations, if it returns true, then skip the current validator Filter\Validation\AbstractCombinedFieldsValidator ¶
-
Namespace
Phalcon\Filter\Validation
-
Uses
-
Extends
AbstractValidator
This is a base class for combined fields validators
Filter\Validation\AbstractValidator ¶
-
Namespace
Phalcon\Filter\Validation
-
Uses
Phalcon\Filter\Validation
Phalcon\Messages\Message
Phalcon\Helper\Arr\Whitelist
-
Extends
-
Implements
ValidatorInterface
This is a base class for validators
Properties¶
/**
* Message template
*
* @var string|null
*/
protected $template;
/**
* Message templates
*
* @var array
*/
protected $templates;
//
protected $options;
Methods¶
Phalcon\Validation\Validator constructor Returns an option in the validator's options Returns null if the option hasn't set Get the template message Get templates collection object Checks if an option is definedpublic function messageFactory( Validation $validation, mixed $field, array $replacements = [] ): Message;
Filter\Validation\AbstractValidatorComposite ¶
-
Namespace
Phalcon\Filter\Validation
-
Uses
Phalcon\Filter\Validation
-
Extends
AbstractValidator
-
Implements
ValidatorCompositeInterface
This is a base class for combined fields validators
Properties¶
Methods¶
Executes the validationFilter\Validation\Exception¶
-
Namespace
Phalcon\Filter\Validation
-
Uses
-
Extends
\Exception
-
Implements
Exceptions thrown in Phalcon\Filter\Validation* classes will use this class
Filter\Validation\ValidationInterface ¶
-
Namespace
Phalcon\Filter\Validation
-
Uses
Phalcon\Di\Injectable
Phalcon\Messages\MessageInterface
Phalcon\Messages\Messages
-
Extends
-
Implements
Interface for the Phalcon\Filter\Validation component
Methods¶
Adds a validator to a field Appends a message to the messages list Assigns the data to an entity The entity is used to obtain the validation values Returns the bound entity Returns all the filters or a specific one Get label for field Returns the registered validators Returns the validators added to the validation Gets the a value to validate in the array/object data source Alias ofadd
method Adds the validators to a field Adds filters to the field Adds labels for fields Validate a set of data according to a set of rules Filter\Validation\Validator\Alnum¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
-
Extends
AbstractValidator
-
Implements
Check for alphanumeric character(s)
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Alnum as AlnumValidator;
$validator = new Validation();
$validator->add(
"username",
new AlnumValidator(
[
"message" => ":field must contain only alphanumeric characters",
]
)
);
$validator->add(
[
"username",
"name",
],
new AlnumValidator(
[
"message" => [
"username" => "username must contain only alphanumeric characters",
"name" => "name must contain only alphanumeric characters",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\Alpha¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Check for alphabetic character(s)
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Alpha as AlphaValidator;
$validator = new Validation();
$validator->add(
"username",
new AlphaValidator(
[
"message" => ":field must contain only letters",
]
)
);
$validator->add(
[
"username",
"name",
],
new AlphaValidator(
[
"message" => [
"username" => "username must contain only letters",
"name" => "name must contain only letters",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\Between¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Validates that a value is between an inclusive range of two values. For a value x, the test is passed if minimum<=x<=maximum.
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Between;
$validator = new Validation();
$validator->add(
"price",
new Between(
[
"minimum" => 0,
"maximum" => 100,
"message" => "The price must be between 0 and 100",
]
)
);
$validator->add(
[
"price",
"amount",
],
new Between(
[
"minimum" => [
"price" => 0,
"amount" => 0,
],
"maximum" => [
"price" => 100,
"amount" => 50,
],
"message" => [
"price" => "The price must be between 0 and 100",
"amount" => "The amount must be between 0 and 50",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\Callback¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Filter\Validation\ValidatorInterface
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Calls user function for validation
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Callback as CallbackValidator;
use Phalcon\Filter\Validation\Validator\Numericality as NumericalityValidator;
$validator = new Validation();
$validator->add(
["user", "admin"],
new CallbackValidator(
[
"message" => "There must be only an user or admin set",
"callback" => function($data) {
if (!empty($data->getUser()) && !empty($data->getAdmin())) {
return false;
}
return true;
}
]
)
);
$validator->add(
"amount",
new CallbackValidator(
[
"callback" => function($data) {
if (!empty($data->getProduct())) {
return new NumericalityValidator(
[
"message" => "Amount must be a number."
]
);
}
}
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\Confirmation¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Filter\Validation\Exception
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Checks that two values have the same value
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Confirmation;
$validator = new Validation();
$validator->add(
"password",
new Confirmation(
[
"message" => "Password doesn't match confirmation",
"with" => "confirmPassword",
]
)
);
$validator->add(
[
"password",
"email",
],
new Confirmation(
[
"message" => [
"password" => "Password doesn't match confirmation",
"email" => "Email doesn't match confirmation",
],
"with" => [
"password" => "confirmPassword",
"email" => "confirmEmail",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validation Compare stringsFilter\Validation\Validator\CreditCard¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Checks if a value has a valid credit card number
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\CreditCard as CreditCardValidator;
$validator = new Validation();
$validator->add(
"creditCard",
new CreditCardValidator(
[
"message" => "The credit card number is not valid",
]
)
);
$validator->add(
[
"creditCard",
"secondCreditCard",
],
new CreditCardValidator(
[
"message" => [
"creditCard" => "The credit card number is not valid",
"secondCreditCard" => "The second credit card number is not valid",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\Date¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
DateTime
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Checks if a value is a valid date
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Date as DateValidator;
$validator = new Validation();
$validator->add(
"date",
new DateValidator(
[
"format" => "d-m-Y",
"message" => "The date is invalid",
]
)
);
$validator->add(
[
"date",
"anotherDate",
],
new DateValidator(
[
"format" => [
"date" => "d-m-Y",
"anotherDate" => "Y-m-d",
],
"message" => [
"date" => "The date is invalid",
"anotherDate" => "The another date is invalid",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\Digit¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Check for numeric character(s)
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Digit as DigitValidator;
$validator = new Validation();
$validator->add(
"height",
new DigitValidator(
[
"message" => ":field must be numeric",
]
)
);
$validator->add(
[
"height",
"width",
],
new DigitValidator(
[
"message" => [
"height" => "height must be numeric",
"width" => "width must be numeric",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\Email¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Checks if a value has a correct e-mail format
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Email as EmailValidator;
$validator = new Validation();
$validator->add(
"email",
new EmailValidator(
[
"message" => "The e-mail is not valid",
]
)
);
$validator->add(
[
"email",
"anotherEmail",
],
new EmailValidator(
[
"message" => [
"email" => "The e-mail is not valid",
"anotherEmail" => "The another e-mail is not valid",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\Exception¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
-
Extends
\Exception
-
Implements
Exceptions thrown in Phalcon\Filter\Validation\Validator* classes will use this class
Filter\Validation\Validator\ExclusionIn¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Filter\Validation\Exception
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Check if a value is not included into a list of values
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\ExclusionIn;
$validator = new Validation();
$validator->add(
"status",
new ExclusionIn(
[
"message" => "The status must not be A or B",
"domain" => [
"A",
"B",
],
]
)
);
$validator->add(
[
"status",
"type",
],
new ExclusionIn(
[
"message" => [
"status" => "The status must not be A or B",
"type" => "The type must not be 1 or "
],
"domain" => [
"status" => [
"A",
"B",
],
"type" => [1, 2],
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\File¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidatorComposite
Phalcon\Filter\Validation\Validator\File\MimeType
Phalcon\Filter\Validation\Validator\File\Resolution\Equal
Phalcon\Filter\Validation\Validator\File\Resolution\Max
Phalcon\Filter\Validation\Validator\File\Resolution\Min
Phalcon\Filter\Validation\Validator\File\Size\Equal
Phalcon\Filter\Validation\Validator\File\Size\Max
Phalcon\Filter\Validation\Validator\File\Size\Min
Phalcon\Messages\Message
Phalcon\Helper\Arr\Get
-
Extends
AbstractValidatorComposite
-
Implements
Checks if a value has a correct file
use Phalcon\Validation;
use Phalcon\Validation\Validator\File as FileValidator;
$validator = new Validation();
$validator->add(
"file",
new FileValidator(
[
"maxSize" => "2M",
"messageSize" => ":field exceeds the max file size (:size)",
"allowedTypes" => [
"image/jpeg",
"image/png",
],
"messageType" => "Allowed file types are :types",
"maxResolution" => "800x600",
"messageMaxResolution" => "Max resolution of :field is :resolution",
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new FileValidator(
[
"maxSize" => [
"file" => "2M",
"anotherFile" => "4M",
],
"messageSize" => [
"file" => "file exceeds the max file size 2M",
"anotherFile" => "anotherFile exceeds the max file size 4M",
"allowedTypes" => [
"file" => [
"image/jpeg",
"image/png",
],
"anotherFile" => [
"image/gif",
"image/bmp",
],
],
"messageType" => [
"file" => "Allowed file types are image/jpeg and image/png",
"anotherFile" => "Allowed file types are image/gif and image/bmp",
],
"maxResolution" => [
"file" => "800x600",
"anotherFile" => "1024x768",
],
"messageMaxResolution" => [
"file" => "Max resolution of file is 800x600",
"anotherFile" => "Max resolution of file is 1024x768",
],
]
)
);
Methods¶
ConstructorFilter\Validation\Validator\File\AbstractFile ¶
-
Namespace
Phalcon\Filter\Validation\Validator\File
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Checks if a value has a correct file
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\File\Size;
$validator = new Validation();
$validator->add(
"file",
new Size(
[
"maxSize" => "2M",
"messageSize" => ":field exceeds the max file size (:size)",
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new FileValidator(
[
"maxSize" => [
"file" => "2M",
"anotherFile" => "4M",
],
"messageSize" => [
"file" => "file exceeds the max file size 2M",
"anotherFile" => "anotherFile exceeds the max file size 4M",
],
]
)
);
Properties¶
/**
* Empty is empty
*
* @var string
*/
protected $messageFileEmpty = Field :field must not be empty;
/**
* File exceeds the file size set in PHP configuration
*
* @var string
*/
protected $messageIniSize = File :field exceeds the maximum file size;
/**
* File is not valid
*
* @var string
*/
protected $messageValid = Field :field is not valid;
Methods¶
Check upload Check if upload is empty Check if upload is valid Check if uploaded file is larger than PHP allowed size Convert a string like "2.5MB" in bytes Check on emptyFilter\Validation\Validator\File\MimeType¶
-
Namespace
Phalcon\Filter\Validation\Validator\File
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\Exception
Phalcon\Messages\Message
-
Extends
AbstractFile
-
Implements
Checks if a value has a correct file mime type
use Phalcon\Validation;
use Phalcon\Validation\Validator\File\MimeType;
$validator = new Validation();
$validator->add(
"file",
new MimeType(
[
"types" => [
"image/jpeg",
"image/png",
],
"message" => "Allowed file types are :types"
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new MimeType(
[
"types" => [
"file" => [
"image/jpeg",
"image/png",
],
"anotherFile" => [
"image/gif",
"image/bmp",
],
],
"message" => [
"file" => "Allowed file types are image/jpeg and image/png",
"anotherFile" => "Allowed file types are image/gif and image/bmp",
]
]
)
);
Properties¶
Methods¶
Executes the validationFilter\Validation\Validator\File\Resolution\Equal¶
-
Namespace
Phalcon\Filter\Validation\Validator\File\Resolution
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\Validator\File\AbstractFile
Phalcon\Messages\Message
-
Extends
AbstractFile
-
Implements
Checks if a file has the right resolution
use Phalcon\Validation;
use Phalcon\Validation\Validator\File\Resolution\Equal;
$validator = new Validation();
$validator->add(
"file",
new Equal(
[
"resolution" => "800x600",
"message" => "The resolution of the field :field has to be equal :resolution",
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new Equal(
[
"resolution" => [
"file" => "800x600",
"anotherFile" => "1024x768",
],
"message" => [
"file" => "Equal resolution of file has to be 800x600",
"anotherFile" => "Equal resolution of file has to be 1024x768",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\File\Resolution\Max¶
-
Namespace
Phalcon\Filter\Validation\Validator\File\Resolution
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\Validator\File\AbstractFile
Phalcon\Messages\Message
-
Extends
AbstractFile
-
Implements
Checks if a file has the right resolution
use Phalcon\Validation;
use Phalcon\Validation\Validator\File\Resolution\Max;
$validator = new Validation();
$validator->add(
"file",
new Max(
[
"resolution" => "800x600",
"message" => "Max resolution of :field is :resolution",
"included" => true,
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new Max(
[
"resolution" => [
"file" => "800x600",
"anotherFile" => "1024x768",
],
"included" => [
"file" => false,
"anotherFile" => true,
],
"message" => [
"file" => "Max resolution of file is 800x600",
"anotherFile" => "Max resolution of file is 1024x768",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\File\Resolution\Min¶
-
Namespace
Phalcon\Filter\Validation\Validator\File\Resolution
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\Validator\File\AbstractFile
Phalcon\Messages\Message
-
Extends
AbstractFile
-
Implements
Checks if a file has the right resolution
use Phalcon\Validation;
use Phalcon\Validation\Validator\File\Resolution\Min;
$validator = new Validation();
$validator->add(
"file",
new Min(
[
"resolution" => "800x600",
"message" => "Min resolution of :field is :resolution",
"included" => true,
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new Min(
[
"resolution" => [
"file" => "800x600",
"anotherFile" => "1024x768",
],
"included" => [
"file" => false,
"anotherFile" => true,
],
"message" => [
"file" => "Min resolution of file is 800x600",
"anotherFile" => "Min resolution of file is 1024x768",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\File\Size\Equal¶
-
Namespace
Phalcon\Filter\Validation\Validator\File\Size
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\Validator\File\AbstractFile
-
Extends
AbstractFile
-
Implements
Checks if a value has a correct file
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\File\Size;
$validator = new Validation();
$validator->add(
"file",
new Equal(
[
"size" => "2M",
"included" => true,
"message" => ":field exceeds the equal file size (:size)",
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new Equal(
[
"size" => [
"file" => "2M",
"anotherFile" => "4M",
],
"included" => [
"file" => false,
"anotherFile" => true,
],
"message" => [
"file" => "file does not have the right file size",
"anotherFile" => "anotherFile wrong file size (4MB)",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\File\Size\Max¶
-
Namespace
Phalcon\Filter\Validation\Validator\File\Size
-
Uses
-
Extends
Equal
-
Implements
Checks if a value has a correct file
use Phalcon\Validation;
use Phalcon\Validation\Validator\File\Size;
$validator = new Validation();
$validator->add(
"file",
new Max(
[
"size" => "2M",
"included" => true,
"message" => ":field exceeds the max file size (:size)",
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new Max(
[
"size" => [
"file" => "2M",
"anotherFile" => "4M",
],
"included" => [
"file" => false,
"anotherFile" => true,
],
"message" => [
"file" => "file exceeds the max file size 2M",
"anotherFile" => "anotherFile exceeds the max file size 4M",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\File\Size\Min¶
-
Namespace
Phalcon\Filter\Validation\Validator\File\Size
-
Uses
-
Extends
Equal
-
Implements
Checks if a value has a correct file
use Phalcon\Validation;
use Phalcon\Validation\Validator\File\Size;
$validator = new Validation();
$validator->add(
"file",
new Min(
[
"size" => "2M",
"included" => true,
"message" => ":field exceeds the min file size (:size)",
]
)
);
$validator->add(
[
"file",
"anotherFile",
],
new Min(
[
"size" => [
"file" => "2M",
"anotherFile" => "4M",
],
"included" => [
"file" => false,
"anotherFile" => true,
],
"message" => [
"file" => "file exceeds the min file size 2M",
"anotherFile" => "anotherFile exceeds the min file size 4M",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\Identical¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Checks if a value is identical to other
use Phalcon\Validation;
use Phalcon\Validation\Validator\Identical;
$validator = new Validation();
$validator->add(
"terms",
new Identical(
[
"accepted" => "yes",
"message" => "Terms and conditions must be accepted",
]
)
);
$validator->add(
[
"terms",
"anotherTerms",
],
new Identical(
[
"accepted" => [
"terms" => "yes",
"anotherTerms" => "yes",
],
"message" => [
"terms" => "Terms and conditions must be accepted",
"anotherTerms" => "Another terms must be accepted",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\InclusionIn¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Filter\Validation\Exception
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Check if a value is included into a list of values
use Phalcon\Validation;
use Phalcon\Validation\Validator\InclusionIn;
$validator = new Validation();
$validator->add(
"status",
new InclusionIn(
[
"message" => "The status must be A or B",
"domain" => ["A", "B"],
]
)
);
$validator->add(
[
"status",
"type",
],
new InclusionIn(
[
"message" => [
"status" => "The status must be A or B",
"type" => "The status must be 1 or 2",
],
"domain" => [
"status" => ["A", "B"],
"type" => [1, 2],
]
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\Ip¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Check for IP addresses
use Phalcon\Validation\Validator\Ip as IpValidator;
$validator->add(
"ip_address",
new IpValidator(
[
"message" => ":field must contain only ip addresses",
"version" => IP::VERSION_4 | IP::VERSION_6, // v6 and v4. The same if not specified
"allowReserved" => false, // False if not specified. Ignored for v6
"allowPrivate" => false, // False if not specified
"allowEmpty" => false,
]
)
);
$validator->add(
[
"source_address",
"destination_address",
],
new IpValidator(
[
"message" => [
"source_address" => "source_address must be a valid IP address",
"destination_address" => "destination_address must be a valid IP address",
],
"version" => [
"source_address" => Ip::VERSION_4 | IP::VERSION_6,
"destination_address" => Ip::VERSION_4,
],
"allowReserved" => [
"source_address" => false,
"destination_address" => true,
],
"allowPrivate" => [
"source_address" => false,
"destination_address" => true,
],
"allowEmpty" => [
"source_address" => false,
"destination_address" => true,
],
]
)
);
Constants¶
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\Numericality¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Check for a valid numeric value
use Phalcon\Validation;
use Phalcon\Validation\Validator\Numericality;
$validator = new Validation();
$validator->add(
"price",
new Numericality(
[
"message" => ":field is not numeric",
]
)
);
$validator->add(
[
"price",
"amount",
],
new Numericality(
[
"message" => [
"price" => "price is not numeric",
"amount" => "amount is not numeric",
]
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\PresenceOf¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Validates that a value is not null or empty string
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\PresenceOf;
$validator = new Validation();
$validator->add(
"name",
new PresenceOf(
[
"message" => "The name is required",
]
)
);
$validator->add(
[
"name",
"email",
],
new PresenceOf(
[
"message" => [
"name" => "The name is required",
"email" => "The email is required",
],
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\Regex¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Allows validate if the value of a field matches a regular expression
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Regex as RegexValidator;
$validator = new Validation();
$validator->add(
"created_at",
new RegexValidator(
[
"pattern" => "/^[0-9]{4}[-\/](0[1-9]|1[12])[-\/](0[1-9]|[12][0-9]|3[01])$/",
"message" => "The creation date is invalid",
]
)
);
$validator->add(
[
"created_at",
"name",
],
new RegexValidator(
[
"pattern" => [
"created_at" => "/^[0-9]{4}[-\/](0[1-9]|1[12])[-\/](0[1-9]|[12][0-9]|3[01])$/",
"name" => "/^[a-z]$/",
],
"message" => [
"created_at" => "The creation date is invalid",
"name" => "The name is invalid",
]
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\StringLength¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Filter\Validation\AbstractValidatorComposite
Phalcon\Filter\Validation\Exception
Phalcon\Filter\Validation\Validator\StringLength\Max
Phalcon\Filter\Validation\Validator\StringLength\Min
Phalcon\Messages\Message
-
Extends
AbstractValidatorComposite
-
Implements
Validates that a string has the specified maximum and minimum constraints The test is passed if for a string's length L, min<=L<=max, i.e. L must be at least min, and at most max. Since Phalcon v4.0 this validator works like a container
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\StringLength as StringLength;
$validator = new Validation();
$validation->add(
"name_last",
new StringLength(
[
"max" => 50,
"min" => 2,
"messageMaximum" => "We don't like really long names",
"messageMinimum" => "We want more than just their initials",
"includedMaximum" => true,
"includedMinimum" => false,
]
)
);
$validation->add(
[
"name_last",
"name_first",
],
new StringLength(
[
"max" => [
"name_last" => 50,
"name_first" => 40,
],
"min" => [
"name_last" => 2,
"name_first" => 4,
],
"messageMaximum" => [
"name_last" => "We don't like really long last names",
"name_first" => "We don't like really long first names",
],
"messageMinimum" => [
"name_last" => "We don't like too short last names",
"name_first" => "We don't like too short first names",
],
"includedMaximum" => [
"name_last" => false,
"name_first" => true,
],
"includedMinimum" => [
"name_last" => false,
"name_first" => true,
]
]
)
);
Methods¶
ConstructorFilter\Validation\Validator\StringLength\Max¶
-
Namespace
Phalcon\Filter\Validation\Validator\StringLength
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Filter\Validation\Exception
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Validates that a string has the specified maximum constraints The test is passed if for a string's length L, L<=max, i.e. L must be at most max.
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\StringLength\Max;
$validator = new Validation();
$validation->add(
"name_last",
new Max(
[
"max" => 50,
"message" => "We don't like really long names",
"included" => true
]
)
);
$validation->add(
[
"name_last",
"name_first",
],
new Max(
[
"max" => [
"name_last" => 50,
"name_first" => 40,
],
"message" => [
"name_last" => "We don't like really long last names",
"name_first" => "We don't like really long first names",
],
"included" => [
"name_last" => false,
"name_first" => true,
]
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\StringLength\Min¶
-
Namespace
Phalcon\Filter\Validation\Validator\StringLength
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Filter\Validation\Exception
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Validates that a string has the specified minimum constraints The test is passed if for a string's length L, min<=L, i.e. L must be at least min.
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\StringLength\Min;
$validator = new Validation();
$validation->add(
"name_last",
new Min(
[
"min" => 2,
"message" => "We want more than just their initials",
"included" => true
]
)
);
$validation->add(
[
"name_last",
"name_first",
],
new Min(
[
"min" => [
"name_last" => 2,
"name_first" => 4,
],
"message" => [
"name_last" => "We don't like too short last names",
"name_first" => "We don't like too short first names",
],
"included" => [
"name_last" => false,
"name_first" => true,
]
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\Validator\Uniqueness¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractCombinedFieldsValidator
Phalcon\Filter\Validation\Exception
Phalcon\Messages\Message
Phalcon\Mvc\Model
Phalcon\Mvc\ModelInterface
-
Extends
AbstractCombinedFieldsValidator
-
Implements
Check that a field is unique in the related table
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Uniqueness as UniquenessValidator;
$validator = new Validation();
$validator->add(
"username",
new UniquenessValidator(
[
"model" => new Users(),
"message" => ":field must be unique",
]
)
);
Different attribute from the field:
$validator->add(
"username",
new UniquenessValidator(
[
"model" => new Users(),
"attribute" => "nick",
]
)
);
In model:
Combination of fields in model:
It is possible to convert values before validation. This is useful in situations where values need to be converted to do the database lookup:
$validator->add(
"username",
new UniquenessValidator(
[
"convert" => function (array $values) {
$values["username"] = strtolower($values["username"]);
return $values;
}
]
)
);
Properties¶
Methods¶
Constructor Executes the validation The column map is used in the case to get real column name Uniqueness method used for modelFilter\Validation\Validator\Url¶
-
Namespace
Phalcon\Filter\Validation\Validator
-
Uses
Phalcon\Filter\Validation
Phalcon\Filter\Validation\AbstractValidator
Phalcon\Messages\Message
-
Extends
AbstractValidator
-
Implements
Checks if a value has a url format
use Phalcon\Filter\Validation;
use Phalcon\Filter\Validation\Validator\Url as UrlValidator;
$validator = new Validation();
$validator->add(
"url",
new UrlValidator(
[
"message" => ":field must be a url",
]
)
);
$validator->add(
[
"url",
"homepage",
],
new UrlValidator(
[
"message" => [
"url" => "url must be a url",
"homepage" => "homepage must be a url",
]
]
)
);
Properties¶
Methods¶
Constructor Executes the validationFilter\Validation\ValidatorCompositeInterface ¶
-
Namespace
Phalcon\Filter\Validation
-
Uses
Phalcon\Filter\Validation
-
Extends
-
Implements
This is a base class for combined fields validators
Methods¶
Executes the validation Executes the validationFilter\Validation\ValidatorFactory¶
-
Namespace
Phalcon\Filter\Validation
-
Uses
Phalcon\Factory\AbstractFactory
-
Extends
AbstractFactory
-
Implements
This file is part of the Phalcon Framework.
(c) Phalcon Team team@phalcon.io
For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.
Methods¶
TagFactory constructor. Creates a new instanceFilter\Validation\ValidatorInterface ¶
-
Namespace
Phalcon\Filter\Validation
-
Uses
Phalcon\Filter\Validation
-
Extends
-
Implements
Interface for Phalcon\Filter\Validation\AbstractValidator