From 9c33e4b8682d19ddb7ee12e9e5cec6711d0ee300 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Fri, 19 May 2017 07:04:45 +0000 Subject: [PATCH] verify: Add isAllowedChars to check if a string contains invalid chars git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3700 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- verify.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/verify.php b/verify.php index 7e48fff..46ae271 100644 --- a/verify.php +++ b/verify.php @@ -220,6 +220,35 @@ class verify return true; } + + ///////////////// + // STRINGS // + ///////////////// + /** Check if the provided value is only contains the provided chars. + * All the strings must be in UTF-8 + * @param string $val The string to test + * @param string $allowedChars The allowed chars + */ + public function isAllowedChars ($val, $allowedChars) + { + return \verify::staticIsAllowedChars ($val, $allowedChars); + } + + /** Check if the provided value is only contains the provided chars. + * In static mode + * All the strings must be in UTF-8 + * @param string $val The string to test + * @param string $allowedChars The allowed chars + */ + public function staticIsAllowedChars ($val, $allowedChars) + { + preg_match ('/^['.$allowedChars.']+/u', $val, $matches); + if (isset ($matches[0]) && + mb_strlen ($matches[0]) === mb_strlen ($val)) + return true; + return false; + } + ///////////////// // NUMBERS // /////////////////