本文整理汇总了PHP中Validation::maxLength方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::maxLength方法的具体用法?PHP Validation::maxLength怎么用?PHP Validation::maxLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validation
的用法示例。
在下文中一共展示了Validation::maxLength方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: answerTextValidation
/**
* answerValidation 登録内容の正当性
*
* @param object &$model use model
* @param array $data Validation対象データ
* @param array $question 登録データに対応する項目
* @param array $allAnswers 入力された登録すべて
* @return bool
*/
public function answerTextValidation(&$model, $data, $question, $allAnswers)
{
if (!in_array($question['question_type'], $this->_textValidateType)) {
return true;
}
$ret = true;
// 数値型登録を望まれている場合
if ($question['question_type_option'] == RegistrationsComponent::TYPE_OPTION_NUMERIC) {
if (!Validation::numeric($data['answer_value'])) {
$ret = false;
$model->validationErrors['answer_value'][] = __d('registrations', 'Number required');
}
if ($question['is_range'] == RegistrationsComponent::USES_USE) {
$rangeRes = Validation::range($data['answer_value'], intval($question['min']), intval($question['max']));
if (!$rangeRes) {
$ret = false;
$model->validationErrors['answer_value'][] = sprintf(__d('registrations', 'Please enter the answer between %s and %s.'), $question['min'], $question['max']);
}
}
} else {
if ($question['is_range'] == RegistrationsComponent::USES_USE) {
if (!Validation::minLength($data['answer_value'], intval($question['min'])) || !Validation::maxLength($data['answer_value'], intval($question['max']))) {
$ret = false;
$model->validationErrors['answer_value'][] = sprintf(__d('registrations', 'Please enter the answer between %s letters and %s letters.'), $question['min'], $question['max']);
}
}
}
return $ret;
}
示例2: answerMaxLength
/**
* answerMaxLength 登録が登録フォームが許す最大長を超えていないかの確認
*
* @param object &$model use model
* @param array $data Validation対象データ
* @param array $question 登録データに対応する項目
* @param int $max 最大長
* @return bool
*/
public function answerMaxLength(&$model, $data, $question, $max)
{
if ($question['question_type'] != $this->_myType) {
return true;
}
return Validation::maxLength($data['answer_value'], $max);
}
示例3: checkTextAreaAnswerValue
/**
* checkTextAreaAnswerValue 入力回答の正当性をチェックする
*
* @param object &$model use model
* @param array &$data Postされた回答データ
* @param array &$question 回答データに対応する質問
* @param array &$answers all answer data of this question (for matrix)
* @return array error messages
*/
public function checkTextAreaAnswerValue(&$model, &$data, &$question, &$answers)
{
$errors = array();
if (!Validation::maxLength($data, QuestionnairesComponent::QUESTIONNAIRE_MAX_ANSWER_LENGTH)) {
$errors = array_merge($errors, sprintf(__d('questionnaires', 'the answer is too long. Please enter under %d letters.', QuestionnairesComponent::QUESTIONNAIRE_MAX_ANSWER_LENGTH)));
}
return $errors;
}
示例4: testMaxLength
/**
* testMaxLength method
*
* @return void
*/
public function testMaxLength()
{
$this->assertTrue(Validation::maxLength('ab', 3));
$this->assertTrue(Validation::maxLength('abc', 3));
$this->assertTrue(Validation::maxLength('ÆΔΩЖÇ', 10));
$this->assertFalse(Validation::maxLength('abcd', 3));
$this->assertFalse(Validation::maxLength('ÆΔΩЖÇ', 3));
}
示例5: testInvalidMaxLength
/**
* @testdox maxLength should return false to strings exceeding specified length
*/
public function testInvalidMaxLength()
{
$value = '424242';
$this->assertFalse(Validation::maxLength($value, 5));
}
示例6: validateDependentFields
/**
* Validates that at least one field is not empty
*
* @param string $check field to check
* @param string $params array of fields that are related
* @return boolean true if at least one field has been filled, false otherwise
* @author Jose Diaz-Gonzalez
* @access public
*/
function validateDependentFields(&$model, $check, $params = array())
{
$fieldKey = array_pop(array_keys($check));
$i = count($params['fields']) + 1;
$j = count($params['fields']);
foreach ($params['fields'] as $fieldname) {
if (empty($model->data[$model->alias][$fieldname])) {
$i--;
} else {
if (!Validation::minLength($model->data[$model->alias][$fieldname], $params['minLength']) or !Validation::maxLength($model->data[$model->alias][$fieldname], $params['maxLength'])) {
$j--;
}
}
}
if (empty($model->data[$model->alias][$fieldKey])) {
$i--;
}
if (Validation::minLength($model->data[$model->alias][$fieldKey], $params['minLength'])) {
$j--;
}
if ($i === 0 or $j === 0) {
return false;
}
return true;
}
示例7: checkRange
/**
* checkRange
*
* @param array $question question
* @param string $answer answer value
* @return array error message
*/
public function checkRange($question, $answer)
{
$errors = array();
// 現在の機能は数値型か文字列型のみ
if ($question['question_type_option'] == QuestionnairesComponent::TYPE_OPTION_NUMERIC) {
if ($question['is_range'] == QuestionnairesComponent::USES_USE) {
if (!Validation::range($answer, intval($question['min']), intval($question['max']))) {
$errors[] = sprintf(__d('questionnaires', 'Please enter the answer between %s and %s.', $question['min'], $question['max']));
}
}
} else {
if ($question['is_range'] == QuestionnairesComponent::USES_USE) {
if (!Validation::minLength($answer, intval($question['min'])) || !Validation::maxLength($answer, intval($question['max']))) {
$errors[] = sprintf(__d('questionnaires', 'Please enter the answer between %s letters and %s letters.', $question['min'], $question['max']));
}
}
}
return $errors;
}