1: <?php
2:
3: 4: 5:
6: class Quform_Filter_Digits 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: $pattern = '/[^0-9' . $whiteSpace . ']/';
25:
26: return preg_replace($pattern, '', $value);
27: }
28:
29: 30: 31: 32: 33: 34:
35: public static function getDefaultConfig($key = null)
36: {
37: $config = apply_filters('quform_default_config_filter_digits', array(
38: 'allowWhiteSpace' => false
39: ));
40:
41: $config['type'] = 'digits';
42:
43: if (Quform::isNonEmptyString($key)) {
44: return Quform::get($config, $key);
45: }
46:
47: return $config;
48: }
49: }
50: