当前位置: 首页>>代码示例>>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;未经允许,请勿转载。