PHP code example of michele-angioni / phalcon-validators
1. Go to this page and download the library: Download michele-angioni/phalcon-validators library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
michele-angioni / phalcon-validators example snippets
$data['ip'] = $this->request->getPost('ip');
$validation = new Phalcon\Validation();
$validation->add(
'ip',
new MicheleAngioni\PhalconValidators\IpValidator (
[
'message' => 'The IP is not valid.' // Optional
]
)
);
$messages = $validation->validate($data);
if (count($messages)) {
// Some error occurred, handle messages
}
$data['number'] = $this->request->getPost('number');
$validation = new Phalcon\Validation();
$validation->add(
'number',
new MicheleAngioni\PhalconValidators\NumericValidator (
[
'allowFloat' => true, // Optional, default: false
'allowSign' => true, // Optional, default: false
'min' => 2, // Optional
'min' => 2, // Optional
'max' => 50, // Optional
'message' => 'Only numeric (0-9,.) characters are allowed.', // Optional
'messageMinimum' => 'The value must be at least 2', // Optional
'messageMaximum' => 'The value must be lower than 50' // Optional
]
)
);
$messages = $validation->validate($data);
if (count($messages)) {
// Some error occurred, handle messages
}
// Validation succeeded without errors
$data['text'] = $this->request->getPost('text');
$validation = new Phalcon\Validation();
$validation->add(
'text',
new MicheleAngioni\PhalconValidators\AlphaNumericValidator (
[
'whiteSpace' => true, // Optional, default false
'underscore' => true, // Optional, default false
'minus' => true, // Optional, default false
'min' => 6, // Optional
'max' => 30, // Optional
'message' => 'Validation failed.', // Optional
'messageMinimum' => 'The value must contain at least 6 characters.', // Optional
'messageMaximum' => 'The value can contain maximum 30 characters.' // Optional
]
)
);
$messages = $validation->validate($data);
if (count($messages)) {
// Some error occurred, handle messages
}
// Validation succeeded without errors
$data['text'] = $this->request->getPost('text');
$validation = new Phalcon\Validation();
$validation->add(
'text',
new MicheleAngioni\PhalconValidators\AlphaNamesValidator (
[
'numbers' => true, // Optional, default false
'min' => 6, // Optional
'max' => 30, // Optional
'message' => 'Validation failed.', // Optional
'messageMinimum' => 'The value must contain at least 6 characters.', // Optional
'messageMaximum' => 'The value can contain maximum 30 characters.' // Optional
]
)
);
$messages = $validation->validate($data);
if (count($messages)) {
// Some error occurred, handle messages
}
// Validation succeeded without errors
$data['text'] = $this->request->getPost('text');
$validation = new Phalcon\Validation();
$validation->add(
'text',
new MicheleAngioni\PhalconValidators\AlphaCompleteValidator (
[
'allowBackslashes' => true, // Optional
'allowAt' => true, // Optional
'allowPipes' => true, // Optional
'allowPercentages' => true, // Optional
'allowUrlChars' => true, // Optional
'min' => 6, // Optional
'max' => 30, // Optional
'message' => 'Validation failed.', // Optional
'messageMinimum' => 'The value must contain at least 6 characters.', // Optional
'messageMaximum' => 'The value can contain maximum 30 characters.' // Optional
]
)
);
$messages = $validation->validate($data);
if (count($messages)) {
// Some error occurred, handle messages
}
// Validation succeeded without errors
$data['text'] = $this->request->getPost('text');
$validation = new Phalcon\Validation();
$validation->add(
'text',
new MicheleAngioni\PhalconValidators\FileNameValidator (
[
'allowMultipleDots' => true, // Optional
'allowAllLatin' => true, // Optional
'allowSpaces' => true, // Optional
'min' => 6, // Optional
'max' => 30, // Optional
'message' => 'Validation failed.', // Optional
'messageMinimum' => 'The value must contain at least 6 characters.', // Optional
'messageMaximum' => 'The value can contain maximum 30 characters.' // Optional
]
)
);
$messages = $validation->validate($data);
if (count($messages)) {
// Some error occurred, handle messages
}
// Validation succeeded without errors
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.