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
This commit is contained in:
2017-05-19 07:04:45 +00:00
parent b7334c1cd4
commit 9c33e4b868

View File

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