2020-02-24 18:02:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PIN;
|
|
|
|
|
|
|
|
class Validator {
|
2023-07-01 14:30:02 +00:00
|
|
|
static $regex;
|
|
|
|
static $exactRegex;
|
|
|
|
|
|
|
|
public static function init(){
|
|
|
|
if(!self::$regex) {
|
|
|
|
self::$regex = "/" . trim(file_get_contents('regex.txt')) . "/";
|
|
|
|
self::$exactRegex = "/^" . trim(file_get_contents('regex.txt')) . "$/";
|
|
|
|
}
|
|
|
|
}
|
2020-03-13 12:19:02 +00:00
|
|
|
|
2020-02-24 18:02:18 +00:00
|
|
|
public static function validate(string $pin) {
|
2023-07-01 14:30:02 +00:00
|
|
|
self::init();
|
|
|
|
|
|
|
|
fwrite(STDERR, var_dump(self::$exactRegex, TRUE));
|
2020-02-24 18:02:18 +00:00
|
|
|
|
2023-07-01 14:30:02 +00:00
|
|
|
if (strlen($pin) === 6 and preg_match(self::$exactRegex, $pin) === 1) {
|
|
|
|
return true;
|
2020-02-24 18:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2023-07-01 14:30:02 +00:00
|
|
|
|
|
|
|
public static function search(string $address) {
|
|
|
|
self::init();
|
|
|
|
preg_match_all(self::$regex, $address, $matches);
|
|
|
|
|
|
|
|
return array_map(function($match) {
|
|
|
|
return $match[0];
|
|
|
|
}, $matches);
|
|
|
|
}
|
2020-03-13 12:19:02 +00:00
|
|
|
}
|