當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Validator::alpha方法代碼示例

本文整理匯總了PHP中Respect\Validation\Validator::alpha方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validator::alpha方法的具體用法?PHP Validator::alpha怎麽用?PHP Validator::alpha使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Respect\Validation\Validator的用法示例。


在下文中一共展示了Validator::alpha方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: isValid

 public function isValid($validation_data)
 {
     $errors = "";
     foreach ($validation_data as $name => $value) {
         $rules = explode("|", $value);
         foreach ($rules as $rule) {
             $exploded = explode(":", $rule);
             switch ($exploded[0]) {
                 case 'min':
                     $min = $exploded[1];
                     if (Valid::alpha()->length($min)->Validate($_POST[$name]) == false) {
                         $errors[] = $name . " must be at least " . $exploded[1] . " characters long!";
                     }
                     break;
                 case 'email':
                     if (Valid::email()->validate($_POST[$name]) == false) {
                         $errors[] = $name . " must be a valid email address!";
                     }
                     break;
                 case 'equalTo':
                     if (Valid::equals($_POST[$name])->validate($_POST[$exploded[1]]) == false) {
                         $errors[] = $name . "'s don't match!";
                     }
                     break;
                 default:
                     $errors[] = "No value found!";
                     break;
             }
         }
     }
     return $errors;
 }
開發者ID:jurajvuk,項目名稱:acme,代碼行數:32,代碼來源:Validator.php

示例2: alpha

 /**
  * 檢查字符串是否隻包含字母
  *
  * @param  string $value
  * @return bool
  */
 public static function alpha($value)
 {
     return Validator::alpha()->validate($value);
 }
開發者ID:tourze,項目名稱:base,代碼行數:10,代碼來源:Valid.php

示例3: prototyper_validate_type

/**
 * Validates input type
 *
 * @param string           $hook       "validate:type"
 * @param string           $type       "prototyper"
 * @param ValidationStatus $validation Current validation status
 * @param array            $params     Hook params
 * @return ValidationStatus
 */
function prototyper_validate_type($hook, $type, $validation, $params)
{
    if (!$validation instanceof ValidationStatus) {
        $validation = new ValidationStatus();
    }
    $field = elgg_extract('field', $params);
    if (!$field instanceof Field) {
        return $validation;
    }
    $rule = elgg_extract('rule', $params);
    if ($rule != "type") {
        return $validation;
    }
    $value = elgg_extract('value', $params);
    $expectation = elgg_extract('expectation', $params);
    switch ($expectation) {
        case 'text':
        case 'string':
            if (!v::string()->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:string', array($field->getLabel())));
            }
            break;
        case 'alnum':
        case 'alphanum':
            if (!v::alnum()->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:alnum', array($field->getLabel())));
            }
            break;
        case 'alpha':
            if (!v::alpha()->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:alpha', array($field->getLabel())));
            }
            break;
        case 'number':
        case 'numeric':
            if (!v::numeric()->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:numeric', array($field->getLabel())));
            }
            break;
        case 'integer':
        case 'int':
            if (!v::int()->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:int', array($field->getLabel())));
            }
            break;
        case 'date':
            if (!v::date()->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:date', array($field->getLabel())));
            }
            break;
        case 'url':
            if (!v::filterVar(FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:url', array($field->getLabel())));
            }
            break;
        case 'email':
            if (!v::filterVar(FILTER_VALIDATE_EMAIL)->validate($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:email', array($field->getLabel())));
            }
            break;
        case 'guid':
        case 'entity':
            if (!elgg_entity_exists($value)) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:guid', array($field->getLabel())));
            }
            break;
        case 'image':
            $type = elgg_extract('type', $value);
            if (!$type || substr_count($type, 'image/') == 0) {
                $validation->setFail(elgg_echo('prototyper:validate:error:type:image', array($field->getLabel())));
            }
            break;
    }
    return $validation;
}
開發者ID:hypejunction,項目名稱:hypeprototypervalidators,代碼行數:84,代碼來源:hooks.php

示例4: testValidationNotExistingParameter

 public function testValidationNotExistingParameter()
 {
     $notExistingValidator = v::alpha();
     $validators = array('notExisting' => $notExistingValidator);
     $mw = new Validation($validators);
     $next = function ($req, $res) {
         return $res;
     };
     $response = $mw($this->request, $this->response, $next);
     $errors = array('notExisting' => array('null must contain only letters (a-z)'));
     $this->assertTrue($mw->hasErrors());
     $this->assertEquals($errors, $mw->getErrors());
 }
開發者ID:DavidePastore,項目名稱:Slim-Validation,代碼行數:13,代碼來源:ValidationTest.php

示例5: validAlpha

 /**
  * Verifica se o valor possui apenas caracteres de a-Z e espaços
  * @param string $value
  * @param array $params Lista de flags
  * @return boolean
  */
 public function validAlpha($value, $params = array())
 {
     if (!v::alpha()->validate($value)) {
         if (getValueFromArray($params, Flag::NOWHITESPACE, false)) {
             Factory::log()->warn('Valor deve possuir apenas letras');
         } else {
             Factory::log()->warn('Valor deve possuir apenas letras, números e espaços');
         }
         return false;
     }
     return true;
 }
開發者ID:diego3,項目名稱:myframework-core,代碼行數:18,代碼來源:DatatypeStringBase.php


注:本文中的Respect\Validation\Validator::alpha方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。