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 // /////////////////