protected function filter($value)
    {
        if (!is_scalar($value)) {
            return $value;
        }
        $value = (string) $value;

        if (!$this->hasPcreUnicodeSupport()) {
            // POSIX named classes are not supported, use alternative 0-9 match
            return preg_replace('/[^0-9]/', '', $value);
        }
        
        if (extension_loaded('mbstring')) {
            // Filter for the value with mbstring
            return preg_replace('/[^[:digit:]]/', '', $value);
        }
        
        // Filter for the value without mbstring
        return preg_replace('/[\p{^N}]/', '', $value);
    }