1: <?php
2:
3: 4: 5:
6: class Quform_Filter_AlphaNumeric extends Quform_Filter_Abstract
7: {
8: 9: 10: 11: 12: 13: 14: 15:
16: public function filter($value)
17: {
18: if ( ! is_string($value)) {
19: return $value;
20: }
21:
22: $whiteSpace = $this->config('allowWhiteSpace') ? '\s' : '';
23:
24: if (Quform::hasPcreUnicodeSupport()) {
25:
26: $pattern = '/[^\p{L}\p{N}' . $whiteSpace . ']/u';
27: } else {
28: $pattern = '/[^a-zA-Z0-9' . $whiteSpace . ']/';
29: }
30:
31: return preg_replace($pattern, '', $value);
32: }
33:
34: 35: 36: 37: 38: 39:
40: public static function getDefaultConfig($key = null)
41: {
42: $config = apply_filters('quform_default_config_filter_alpha_numeric', array(
43: 'allowWhiteSpace' => false
44: ));
45:
46: $config['type'] = 'alphaNumeric';
47:
48: if (Quform::isNonEmptyString($key)) {
49: return Quform::get($config, $key);
50: }
51:
52: return $config;
53: }
54: }
55: