mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 23:35:45 +01:00
24 lines
464 B
PHP
24 lines
464 B
PHP
<?php
|
|
namespace Respect\Validation\Rules;
|
|
|
|
class PrimeNumber extends AbstractRule
|
|
{
|
|
public function validate($input)
|
|
{
|
|
if (!is_numeric($input) || $input <= 1) {
|
|
return false;
|
|
}
|
|
|
|
if ($input != 2 && ($input % 2) == 0) {
|
|
return false;
|
|
}
|
|
|
|
for ($i = 2; $i < $input; $i++) {
|
|
if (($input % $i) == 0) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|