mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
Most changes was made by php-cs-fixer. Also removes unused `RecursiveTreeIterator` class.
28 lines
574 B
PHP
28 lines
574 B
PHP
<?php
|
|
namespace Respect\Validation\Rules;
|
|
|
|
class PrimeNumber extends AbstractRule
|
|
{
|
|
public function validate($input)
|
|
{
|
|
if (is_numeric($input) && $input > 0) {
|
|
$cont = 0;
|
|
|
|
for ($i = 1; $i <= $input; $i++) {
|
|
if (($input % $i) == 0) {
|
|
$cont = $cont + 1;
|
|
}
|
|
}
|
|
|
|
if ($cont <= 2) {
|
|
$input = 1;
|
|
} else {
|
|
$input = 0;
|
|
}
|
|
} else {
|
|
$input = 0;
|
|
}
|
|
|
|
return (boolean) $input;
|
|
}
|
|
}
|