Beispiel #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, '' => false);
     foreach ($valuesExpected as $input => $result) {
         $this->assertEquals($result, $this->_validator->isValid($input));
     }
 }
Beispiel #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");
     }
 }
 /**
  * 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;
 }
Beispiel #4
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;
 }
Beispiel #5
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;
     }
 }
Beispiel #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');
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Beispiel #9
0
$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'])){
            $tpl['addcall']['errors'][] = "Сегодня Вы уже оставляли заявку на обратный звонок!";
        } else {
            $data = array('fio' => $tpl['addcall']['callfio'],
                'phone' => $tpl['addcall']['callphone'],
                'date' => time());
            $calls->addNewRecord($data);
            $tpl['addcall']['send_status'] = true;

            /*if(workTimeInterval::ocenkaWork()){
                
Beispiel #10
0
 /**
  * @ZF-4352
  */
 public function testNonStringValidation()
 {
     $this->assertFalse($this->_validator->isValid(array(1 => 1)));
 }
Beispiel #11
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;
 }
Beispiel #12
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);
 }
Beispiel #13
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);
 }
Beispiel #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;
 }
Beispiel #15
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;
 }