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: * (Czech and Slovak) phone number validator.
16: *
17: * @category Jyxo
18: * @package Jyxo_Input
19: * @subpackage Validator
20: * @copyright Copyright (c) 2005-2011 Jyxo, s.r.o.
21: * @license https://github.com/jyxo/php/blob/master/license.txt
22: * @author Jaroslav Hanslík
23: * @author Jakub Tománek
24: */
25: class Jyxo_Input_Validator_IsPhone extends Jyxo_Input_Validator_AbstractValidator
26: {
27: /**
28: * Validates a value.
29: *
30: * @param mixed $value Input value
31: * @return boolean
32: */
33: public function isValid($value)
34: {
35: // Removes spaces
36: $phoneNumber = preg_replace('~\s+~', '', (string) $value);
37:
38: if (preg_match('~^1\d{2,8}$~', $phoneNumber)) {
39: // Special numbers
40: return true;
41: } elseif (preg_match('~^8\d{8}$~', $phoneNumber)) {
42: // Numbers with special tariffs
43: return true;
44: } elseif (preg_match('~^(?:(?:[+]|00)42(?:0|1))?[2-79]\d{8}$~', $phoneNumber)) {
45: // Normal numbers
46: return true;
47: } else {
48: return false;
49: }
50: }
51: }
52: