PHP code example of wijoc / validify-mi
1. Go to this page and download the library: Download wijoc/validify-mi 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/ */
wijoc / validify-mi example snippets
Wijoc\ValidifyMI\Validator;
$input = [
'email' => '[email protected] ',
'age' => 25
];
$rules = [
'email' => [' is invalid!",
'age.press sanitize)
*/
$validator = Validator::make($input, $rules, $message);
if ($validator->fails()) {
/** Validation failed */
print_r($validator->errors('all'));
/** Get first error */
$validator->errors()->firstOfAll();
} else {
/** Validation passed */
echo "Validation successful!";
/** get validated data */
$validated = $validator->validate();
}
Wijoc\ValidifyMI\Validator;
$input = [
'email' => '[email protected] ',
'age' => 25,
'phoneNumber' => [
'123456789',
'987654321'
],
'socialMedia' => [
'facebook' => 'https://facebook.com',
'twitter' => 'https://twitter.com'
],
'address' => [
[
'city' => 'Jakarta',
'province' => 'DKI Jakarta',
'postalCode' => '123'
]
]
];
$rules = [
'email' => ['can add sanitizer as 4th arguments
* * (for now it's limited to wordpress sanitize)
*/
$validator = Validator::make($input, $rules, $message);
if ($validator->fails()) {
/** Validation failed */
print_r($validator->errors('all'));
} else {
/** Validation passed */
echo "Validation successful!";
}
/** Input Value to validate */
$input = [
'email' => '[email protected] ',
'age' => 25
];
/** Validation Rule */
$rules = [
'email' => ['
$message = [
'email.il is invalid!",
'age.
/** Create validator
* * You can add sanitizer as 4th arguments
* * (for now it's limited to wordpress sanitize)
*/
$validator = Validator::make($input, $rules, $message);
/** Using validate() function */
$validator->validate()
/** Using fails function */
$validator->fails()
if ($validator->fails()) {
/** Validation failed */
print_r($validator->errors('all'));
} else {
/** Validation passed */
echo "Validation successful!";
}
if ($validator->fails()) {
/** Validation failed */
print_r($validator->errors('all'));
} else {
/** Validation passed */
echo "Validation successful!";
}
if ($validator->fails()) {
/** Validation failed */
print_r($validator->errors()->firstOfAll());
// print_r($validator->errors('all')->firstOfAll()); -> This will result an exception
} else {
/** Validation passed */
echo "Validation successful!";
}
if ($validator->fails()) {
/** Validation failed */
print_r($validator->errors()->firstOfAll());
// print_r($validator->errors('all')->firstOfAll()); -> This will result an exception
} else {
/** Validation passed */
echo "Validation successful!";
/** get validated */
$validated = $validator->validated();
print_r($validated);
}
$rules = [
'input' => ['
$rules = [
'input' => ['email']
];
$rules = [
'input' => ['url']
];
$rules = [
'input' => ['numeric']
];
$rules = [
'input' => ['max:9']
];
$rules = [
'input' => ['min:9']
];
$rules = [
'input' => ['greater_than:9']
];
$rules = [
'input' => ['gt:9']
];
$rules = [
'input' => ['greater_than_equal:9']
];
$rules = [
'input' => ['gte:9']
];
$rules = [
'input' => ['less_than:9']
];
$rules = [
'input' => ['lt:9']
];
$rules = [
'input' => ['less_than_equal:9']
];
$rules = [
'input' => ['lte:9']
];
$rules = [
'input' => ['compare_number:{operator},{parameter to compare}']
];
$rules = [
'input' => ['compare_number:>,9']
];
$rules = [
'input' => ['date:{date format}']
];
$rules = [
'input' => ['date:Y-m-d H:i:s']
];
$rules = [
'input' => ['date_more_than:{date or request field},{date format}']
];
$rules = [
'input' => ['date_more_than:2024-12-01 01:59:59, Y-m-d H:i:s']
];
$request = [
'inputToCompare' => '2024-01-30',
'input' => '2024-12-31',
];
$rules = [
'input' => ['date_more_than:inputToCompare, Y-m-d']
];
$rules = [
'input' => ['date_less_than:{date or request field},{date format}']
];
$rules = [
'input' => ['date_less_than:2024-12-01 01:59:59,Y-m-d H:i:s']
];
$request = [
'inputToCompare' => '2024-01-30',
'input' => '2024-12-31',
];
$rules = [
'input' => ['date_less_than:inputToCompare,Y-m-d']
];
$rules = [
'input' => ['date_between:{start date or request field},{end date or request field},{date format}']
];
$rules = [
'input' => ['date_between:2024-12-01 01:59:59,2024-12-31 01:59:59,Y-m-d H:i:s']
];
$request = [
'inputStart' => '2024-01-01',
'inputEnd' => '2024-01-30',
'input' => '2024-12-31',
];
$rules = [
'input' => ['date_between:inputStart,inputEnd,Y-m-d']
];
$rule = [
'input' => ['match:{request field}'];
];
$request = [
'inputToCompare' => 'value to compare',
'input' => 'value input'
];
$rule = [
'input' => ['match:inputToCompare'];
];
$rule = [
'input' => ['not_match:{request field}'];
];
$request = [
'inputToCompare' => 'value to compare',
'input' => 'value input'
];
$rule = [
'input' => ['not_match:inputToCompare'];
];
$rule = [
'input' => ['files'];
];
$rule = [
'input' => ['file'];
];
$rule = [
'input' => ['is_file'];
];
$rule = [
'input' => ['max_file_size:{size in KB}'];
];
$rule = [
'input' => ['max_file_size:20'];
];
$rule = [
'input' => ['mime:{mime type}'];
];
$rule = [
'input' => ['mime:image/png,image/jpeg,application/pdf'];
];
$rule = [
'input' => ['in:value1,value2'];
];
$rule = [
'input' => ['regex:^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+])(?=\S+$).*'];
];
Wijoc\ValidifyMI\Validator;
$input = [
'email' => '[email protected] ',
'age' => 25,
'phoneNumber' => [
'123456789',
'987654321'
],
'socialMedia' => [
'facebook' => 'https://facebook.com',
'twitter' => 'https://twitter.com'
],
'address' => [
[
'city' => 'Jakarta',
'province' => 'DKI Jakarta',
'postalCode' => '123'
]
]
];
$rules = [
'email' => ['email'
'age' => 'text'
'phoneNumber.*' => 'text',
'socialMedia.facebook' => 'text',
'address.*.province' => 'kses'
];
/** Create validator
* * You can add sanitizer as 4th arguments
* * (for now it's limited to wordpress sanitize)
*/
$validator = Validator::make($input, $rules, $message, $sanitizer);
if ($validator->fails()) {
/** Validation failed */
print_r($validator->errors('all'));
} else {
/** get validated data */
$validated = $validator->validated();
/** get sanitized data */
$sanitized = $validator->sanitized();
}
$sanitizer = [
'input' => 'email'
];
$sanitizer = [
'input' => 'textarea'
];
$sanitizer = [
'input' => 'text'
];
$sanitizer = [
'input' => 'kses'
];
$sanitizer = [
'input' => 'ksespost'
];