From 4f30d343e5997de9f826ac85306c1b6be0868f3f Mon Sep 17 00:00:00 2001 From: Netkas Date: Sun, 18 Dec 2022 00:12:45 -0500 Subject: [PATCH] Added method \ncc\Utilities > Validate > pathName() https://git.n64.cc/nosial/ncc/-/issues/4 --- src/ncc/Utilities/Validate.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/ncc/Utilities/Validate.php b/src/ncc/Utilities/Validate.php index 46297a0..838555c 100644 --- a/src/ncc/Utilities/Validate.php +++ b/src/ncc/Utilities/Validate.php @@ -268,6 +268,8 @@ */ public static function nameFriendly(string $input): bool { + if(strlen($input) == 0) + return false; if (!preg_match('/^[a-zA-Z0-9_]+$/', $input)) return false; if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $input)) @@ -275,4 +277,22 @@ return true; } + + /** + * Validates if the given input is a valid path name + * + * @param string $input + * @return bool + */ + public static function pathName(string $input): bool + { + if(strlen($input) == 0) + return false; + if (!preg_match('/^[a-zA-Z0-9_\-\/]+$/', $input)) + return false; + if (!preg_match('/^[a-zA-Z_\-\/][a-zA-Z0-9_\-\/]*$/', $input)) + return false; + + return true; + } } \ No newline at end of file