<?php

class Eppe_Validate_PolishPhoneNumber extends Zend_Validate_Abstract {

	const INVALID_NIP_NUMBER = 'invalidPhoneNumber';

	protected $_messageTemplates = array(
		self::INVALID_NIP_NUMBER => "'%value%' is not a valid polish Phone number code.",
	);
	
	public function __construct($options = null) {
		Eppe_Validate::setupConstructorOptions($this, $options);
	}

	/**
	 * @param type $value
	 * @return boolean
	 */
	public function isValid($value) {
		$valueString = (string) $value;
		$this->_setValue($valueString);

		if (!$this->isPhoneValid($value)) {
			$this->_error(self::INVALID_NIP_NUMBER);
			return false;
		}
		return true;
	}

	/**
	 * Sprawdza poprawność podanego numeru telefonu
	 * @param string $phone
	 * @return boolean
	 */
	public function isPhoneValid($phone) {
		$phone = str_replace(' ', '', $phone);
		if(preg_match('/[0-9]/', $phone))
				return true;
		
		return false;
	}

}

?>
