1: <?php
2:
3: /**
4: * Jyxo PHP Library
5: *
6: * LICENSE
7: *
8: * This source file is subject to the new BSD license that is bundled
9: * with this package in the file license.txt.
10: * It is also available through the world-wide-web at this URL:
11: * https://github.com/jyxo/php/blob/master/license.txt
12: */
13:
14: /**
15: * Filters phone numbers. Removes spaces and adds the pre-dial where possible.
16: *
17: * @category Jyxo
18: * @package Jyxo_Input
19: * @subpackage Filter
20: * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
21: * @license https://github.com/jyxo/php/blob/master/license.txt
22: * @author Jakub Tománek
23: */
24: class Jyxo_Input_Filter_Phone extends Jyxo_Input_Filter_AbstractFilter
25: {
26: /**
27: * Filters a value.
28: *
29: * @param mixed $value Input value
30: * @return mixed
31: */
32: protected function filterValue($value)
33: {
34: // Removes spaces
35: $value = preg_replace('~\s+~', '', (string) $value);
36:
37: // Adds the Czech pre-dial where possible
38: if (preg_match('~^[2-79]\d{8}$~', $value)) {
39: $value = '+420' . $value;
40: }
41:
42: return $value;
43: }
44: }
45: