Пример #1
0
 /**
  * Ensures that the validator follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     $valuesExpected = array('abc123' => false, 'abc 123' => false, 'abcxyz' => true, 'AZ@#4.3' => false, 'aBc123' => false, 'aBcDeF' => true);
     foreach ($valuesExpected as $input => $result) {
         $this->assertEquals($result, $this->_validator->isValid($input));
     }
 }
Пример #2
0
 /**
  * Ensures that the allowWhiteSpace option works as expected
  *
  * @return void
  */
 public function testAllowWhiteSpace()
 {
     $this->_validator->allowWhiteSpace = true;
     $valuesExpected = array('abc123' => false, 'abc 123' => false, 'abcxyz' => true, 'AZ@#4.3' => false, 'aBc123' => false, 'aBcDeF' => true, '' => false, ' ' => true, "\n" => true, " \t " => true, "a\tb c" => true);
     foreach ($valuesExpected as $input => $result) {
         $this->assertEquals($result, $this->_validator->isValid($input), "Expected '{$input}' to be considered " . ($result ? '' : 'in') . "valid");
     }
 }
Пример #3
0
 public function isValid($sValue)
 {
     $sValue = preg_replace("/_/", " ", $sValue);
     $oAlphaValidator = new Zend_Validate_Alpha(array("allowWhiteSpace" => true));
     if ($oAlphaValidator->isValid($sValue)) {
         return true;
     }
     return false;
 }
Пример #4
0
 function alpha_all_language($elem)
 {
     include_once LIBRARY . "Zend/Validate/Alpha.php";
     $validator = new Zend_Validate_Alpha(array('allowWhiteSpace' => true));
     if ($validator->isValid($elem['value'])) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Validate attributes
  * 
  * @param string $validation attribute validation class name
  * @param string $value attribute value
  * @return array returns success and errors as array keys
  */
 protected function validateAttributeValue($validation, $value)
 {
     $valid = array('success' => TRUE, 'errors' => '');
     switch ($validation) {
         case Fox_Eav_Model_Attribute::ATTRIBUTE_VALIDATION_DECIMAL:
             if (!$this->decimalValidation) {
                 $this->decimalValidation = new Zend_Validate_Float();
             }
             $valid['success'] = $this->decimalValidation->isValid($value);
             $valid['errors'] = '"' . $value . '" contains invalid digits.';
             break;
         case Fox_Eav_Model_Attribute::ATTRIBUTE_VALIDATION_EMAIL:
             if (!$this->emailValidation) {
                 $this->emailValidation = new Zend_Validate_EmailAddress();
             }
             $valid['success'] = $this->emailValidation->isValid($value);
             $valid['errors'] = '"' . $value . '" is not a valid email address.';
             break;
         case Fox_Eav_Model_Attribute::ATTRIBUTE_VALIDATION_INT:
             if (!$this->intValidation) {
                 $this->intValidation = new Zend_Validate_Int();
             }
             $valid['success'] = $this->intValidation->isValid($value);
             $valid['errors'] = '"' . $value . '" is not a valid integer.';
             break;
         case Fox_Eav_Model_Attribute::ATTRIBUTE_VALIDATION_LETTERS:
             if (!$this->letterValidation) {
                 $this->letterValidation = new Zend_Validate_Alpha(true);
             }
             $valid['success'] = $this->letterValidation->isValid($value);
             $valid['errors'] = '"' . $value . '" contains invalid characters.';
             break;
         case Fox_Eav_Model_Attribute::ATTRIBUTE_VALIDATION_DATE:
             $valid['success'] = strtotime($value) > 0;
             $valid['errors'] = '"' . $value . '" is invalid date.';
             break;
         case Fox_Eav_Model_Attribute::ATTRIBUTE_VALIDATION_URL:
             if (!$this->urlValidation) {
                 $this->urlValidation = new Uni_Validate_Url();
             }
             $valid['success'] = $this->urlValidation->isValid($value);
             $valid['errors'] = '"' . $value . '" is not a valid url.';
             break;
         case Fox_Eav_Model_Attribute::ATTRIBUTE_VALIDATION_IMAGE:
             if (empty($this->validExtensions)) {
                 $this->validExtensions = array('jpg', 'jpeg', 'png', 'bmp', 'gif', 'tiff');
             }
             $extPos = strrpos($value, '.');
             if (!$extPos || !empty($this->validExtensions) && !in_array(substr($value, $extPos + 1), $this->validExtensions)) {
                 $valid['success'] = FALSE;
                 $valid['errors'] = 'Invalid image was given.';
             }
             break;
         default:
             break;
     }
     return $valid;
 }
Пример #6
0
 /** Set the types of entity to retrieve data upon
  * @access public
  * @param type $types
  * @throws Pas_Geo_Mapit_Exception
  */
 public function setTypes($types)
 {
     if (is_array($types)) {
         foreach ($types as $type) {
             if (strlen($type) != 3) {
                 throw new Pas_Geo_Mapit_Exception('The area must be a three letter string');
             }
             $validator = new Zend_Validate_Alpha();
             if (!$validator->isValid($type)) {
                 throw new Pas_Geo_Mapit_Exception('Invalid characters used', 500);
             }
             if (!in_array($type, array_flip($this->_allowedTypes))) {
                 throw new Pas_Geo_Mapit_Exception('The area type of ' . $type . ' must be in allowed list');
             }
         }
         $this->_types = implode(',', $types);
     } else {
         throw new Pas_Geo_Mapit_Exception('Areas must be an array');
     }
 }
Пример #7
0
 public function isValid($value)
 {
     $valueString = (string) $value;
     $this->_setValue($valueString);
     if ('' === $valueString) {
         $this->_error(self::STRING_EMPTY);
         return false;
     }
     if (null === self::$_filter) {
         require_once 'Zend/Filter/Alpha.php';
         self::$_filter = new Zend_Filter_Alpha();
     }
     self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
     if ($valueString !== self::$_filter->filter($valueString)) {
         $this->_error(self::NOT_ALPHA);
         return false;
     }
     return true;
 }
Пример #8
0
 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return array|true
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = $this->getAttribute()->getStoreLabel();
     $validateRules = $this->getAttribute()->getValidationRules();
     $inputValidation = ArrayObjectSearch::getArrayElementByName($validateRules, 'input_validation');
     if (!is_null($inputValidation)) {
         switch ($inputValidation) {
             case 'alphanumeric':
                 $validator = new \Zend_Validate_Alnum(true);
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(__('"%1" contains non-alphabetic or non-numeric characters.', $label), \Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new \Zend_Validate_Digits();
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Digits::INVALID);
                 $validator->setMessage(__('"%1" contains non-numeric characters.', $label), \Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new \Zend_Validate_Alpha(true);
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(__('"%1" contains non-alphabetic characters.', $label), \Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 /**
                 __("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded")
                 __("Invalid type given. String expected")
                 __("'%value%' appears to be a DNS hostname but contains a dash in an invalid position")
                 __("'%value%' does not match the expected structure for a DNS hostname")
                 __("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'")
                 __("'%value%' does not appear to be a valid local network name")
                 __("'%value%' does not appear to be a valid URI hostname")
                 __("'%value%' appears to be an IP address, but IP addresses are not allowed")
                 __("'%value%' appears to be a local network name but local network names are not allowed")
                 __("'%value%' appears to be a DNS hostname but cannot extract TLD part")
                 __("'%value%' appears to be a DNS hostname but cannot match TLD against known list")
                 */
                 $validator = new \Zend_Validate_EmailAddress();
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(__('"%1" uses too many characters.', $label), \Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 $validator->setMessage(__("'%value%' looks like an IP address, which is not an acceptable format."), \Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but we cannot match the TLD against known list."), \Zend_Validate_Hostname::UNKNOWN_TLD);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but contains a dash in an invalid position."), \Zend_Validate_Hostname::INVALID_DASH);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but we cannot match it against the hostname schema for TLD '%tld%'."), \Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but cannot extract TLD part."), \Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
                 $validator->setMessage(__("'%value%' does not look like a valid local network name."), \Zend_Validate_Hostname::INVALID_LOCAL_NAME);
                 $validator->setMessage(__("'%value%' looks like a local network name, which is not an acceptable format."), \Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
                 $validator->setMessage(__("'%value%' appears to be a DNS hostname, but the given punycode notation cannot be decoded."), \Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return [__('"%1" is not a valid URL.', $label)];
                 }
                 $validator = new \Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return [__('"%1" is not a valid URL.', $label)];
                 }
                 break;
             case 'date':
                 $validator = new \Zend_Validate_Date(\Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT);
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Date::INVALID);
                 $validator->setMessage(__('"%1" is not a valid date.', $label), \Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(__('"%1" does not fit the entered date format.', $label), \Zend_Validate_Date::FALSEFORMAT);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
         }
     }
     return true;
 }
Пример #9
0
 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return string
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = Mage::helper('customer')->__($this->getAttribute()->getStoreLabel());
     $validateRules = $this->getAttribute()->getValidateRules();
     if (!empty($validateRules['input_validation'])) {
         switch ($validateRules['input_validation']) {
             case 'alphanumeric':
                 $validator = new Zend_Validate_Alnum(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new Zend_Validate_Digits();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new Zend_Validate_Alpha(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 /**
                 $this->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded")
                 $this->__("Invalid type given. String expected")
                 $this->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position")
                 $this->__("'%value%' does not match the expected structure for a DNS hostname")
                 $this->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'")
                 $this->__("'%value%' does not appear to be a valid local network name")
                 $this->__("'%value%' does not appear to be a valid URI hostname")
                 $this->__("'%value%' appears to be an IP address, but IP addresses are not allowed")
                 $this->__("'%value%' appears to be a local network name but local network names are not allowed")
                 $this->__("'%value%' appears to be a DNS hostname but cannot extract TLD part")
                 $this->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list")
                 */
                 $validator = new Zend_Validate_EmailAddress();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be an IP address, but IP addresses are not allowed"), Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list"), Zend_Validate_Hostname::UNKNOWN_TLD);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position"), Zend_Validate_Hostname::INVALID_DASH);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'"), Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot extract TLD part"), Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' does not appear to be a valid local network name"), Zend_Validate_Hostname::INVALID_LOCAL_NAME);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a local network name but local network names are not allowed"), Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded"), Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 $validator = new Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 break;
             case 'date':
                 $validator = new Zend_Validate_Date(Varien_Date::DATE_INTERNAL_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
         }
     }
     return true;
 }
Пример #10
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if $value contains only alphabetic characters
  *
  * @param  string $value
  * @return boolean
  */
 public function isValid($value)
 {
     if (!is_string($value)) {
         $this->_error(self::INVALID);
         return false;
     }
     $this->_setValue($value);
     if ('' === $value) {
         $this->_error(self::STRING_EMPTY);
         return false;
     }
     if (null === self::$_filter) {
         /**
          * @see Zend_Filter_Alpha
          */
         require_once 'Zend/Filter/Alpha.php';
         self::$_filter = new Zend_Filter_Alpha();
     }
     self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
     if ($value !== self::$_filter->filter($value)) {
         $this->_error(self::NOT_ALPHA);
         return false;
     }
     return true;
 }
Пример #11
0
<?
require_once('Zend/Validate/Alpha.php');
require_once($cfg['path'] . '/models/calls.php');
require_once($cfg['path'] . '/helpers/workTimeInterval.php');


$writer = new Zend_Log_Writer_Stream($log_calls);
$logger    = new Zend_Log($writer);

$tpl['addcall']['errors'] = array();
$tpl['addcall']['callfio'] = isset($_REQUEST['callfio'])?$_REQUEST['callfio']:"";
$tpl['addcall']['callphone'] = isset($_REQUEST['callphone'])?$_REQUEST['callphone']:"";

$tpl['addcall']['send_status'] = false;

$validator_text = new Zend_Validate_Alpha(array('allowWhiteSpace' => true));


if($_SERVER['REQUEST_METHOD']=='POST'){
    if(!$tpl['addcall']['callfio']){
        $tpl['addcall']['errors'][] = "Вы не указали имя";
    }
    if(!$tpl['addcall']['callphone']){
        $tpl['addcall']['errors'][] = "Введите номер телефона";
    }
    if(!$validator_text->isValid($tpl['addcall']['callfio'])){
    	$tpl['addcall']['errors'][] = "Поле имя должно содержать только буквы!";
    }
    if(!$tpl['addcall']['errors']){
        $calls = new model_addcall($db_class);
        if($calls->isCallExist($tpl['addcall']['callphone'])){
Пример #12
0
 /**
  * @ZF-4352
  */
 public function testNonStringValidation()
 {
     $this->assertFalse($this->_validator->isValid(array(1 => 1)));
 }
Пример #13
0
 /**
  * @group ZF-9275
  */
 public function testElementsTranslatorDoesntOverrideValidatorsDirectlyAttachedTranslator()
 {
     $elementTranslations = array('alphaInvalid' => 'Element message');
     $elementTranslate = new Zend_Translate('array', $elementTranslations);
     $validatorTranslations = array('alphaInvalid' => 'Direct validator message');
     $validatorTranslate = new Zend_Translate('array', $validatorTranslations);
     $validator = new Zend_Validate_Alpha();
     $validator->setTranslator($validatorTranslate);
     $this->element->addValidator($validator);
     $this->assertFalse($this->element->isValid(123));
     $messages = $this->element->getMessages();
     $this->assertEquals('Direct validator message', $messages['alphaInvalid']);
 }
Пример #14
0
 /**
  * @param  string  $sort
  * @return boolean
  */
 private function validateFilterSort($sort)
 {
     $alphaValidator = new AlphaValidator();
     $alphaValidator->setMessage("Filter sort ist kein String", AlphaValidator::INVALID);
     $alphaValidator->setMessage("Filter sort '%value%' enthält nicht alphabetische Character", AlphaValidator::NOT_ALPHA);
     if (!$alphaValidator->isValid($sort)) {
         $messages = array_values($alphaValidator->getMessages());
         $this->addError(new Error('sort', $sort, $messages));
         return false;
     }
     return true;
 }
Пример #15
0
 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return string
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = $this->getAttribute()->getStoreLabel();
     $validateRules = $this->getAttribute()->getValidateRules();
     if (!empty($validateRules['input_validation'])) {
         switch ($validateRules['input_validation']) {
             case 'alphanumeric':
                 $validator = new Zend_Validate_Alnum(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new Zend_Validate_Digits();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new Zend_Validate_Alpha(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 $validator = new Zend_Validate_EmailAddress();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 $validator = new Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 break;
             case 'date':
                 $format = Mage::app()->getLocale()->getDateFormat(Varien_Date::DATE_INTERNAL_FORMAT);
                 $validator = new Zend_Validate_Date($format);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT);
                 break;
         }
     }
     return true;
 }
Пример #16
0
 /** Set the filter up for method calls
  * @access public
  * @param type $type
  * @return type
  * @throws Pas_Geo_Mapit_Exception
  */
 public function setFilter($type)
 {
     if (strlen($type) != 3) {
         throw new Pas_Geo_Mapit_Exception('The area must be a three letter string');
     }
     $validator = new Zend_Validate_Alpha();
     if (!$validator->isValid($type)) {
         throw new Pas_Geo_Mapit_Exception('Invalid characters used', 500);
     }
     if (!in_array($type, array_flip($this->_allowedTypes))) {
         throw new Pas_Geo_Mapit_Exception('The area type of ' . $type . ' must be in allowed list');
     }
     return $this->_filter = '?type=' . $type;
 }
Пример #17
0
 public function __construct($allowWhiteSpace = false)
 {
     parent::__construct($allowWhiteSpace);
     $this->_messageTemplates[self::NOT_ALPHA] = trlKwfStatic("'%value%' has not only alphabetic characters");
     $this->_messageTemplates[self::STRING_EMPTY] = trlKwfStatic("'%value%' is an empty string");
 }
Пример #18
0
 /**
  * Returns TRUE if every character is alphabetic, FALSE
  * otherwise.
  *
  * @deprecated since 0.8.0
  * @param      mixed $value
  * @return     boolean
  */
 public static function isAlpha($value)
 {
     require_once 'Zend/Validate/Alpha.php';
     $validator = new Zend_Validate_Alpha();
     return $validator->isValid($value);
 }
Пример #19
0
 /**
  * Ensures that getMessages() returns expected default value
  *
  * @return void
  */
 public function testGetMessages()
 {
     $this->assertEquals(array(), $this->_validator->getMessages());
 }
Пример #20
0
 /**
  * Validate fullName
  *
  * @static
  * @param $fullName
  * @return bool
  */
 public static function isValid($fullName)
 {
     $validator = new Zend_Validate_Alpha(array('allowWhiteSpace' => true));
     return $validator->isValid($fullName);
 }