本文整理汇总了PHP中Validation::range方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::range方法的具体用法?PHP Validation::range怎么用?PHP Validation::range使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validation
的用法示例。
在下文中一共展示了Validation::range方法的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: testRange
/**
* testRange method
*
* @return void
*/
public function testRange()
{
$this->assertFalse(Validation::range(20, 100, 1));
$this->assertTrue(Validation::range(20, 1, 100));
$this->assertFalse(Validation::range(0.5, 1, 100));
$this->assertTrue(Validation::range(0.5, 0, 100));
$this->assertTrue(Validation::range(5));
$this->assertTrue(Validation::range(-5, -10, 1));
$this->assertFalse(Validation::range('word'));
}
示例3: testRangeTypeChecks
/**
* Test range type checks
*
* @return void
*/
public function testRangeTypeChecks()
{
$this->assertFalse(Validation::range('\\x028', 1, 5), 'hexish encoding fails');
$this->assertFalse(Validation::range('0b010', 1, 5), 'binary string data fails');
$this->assertFalse(Validation::range('0x01', 1, 5), 'hex string data fails');
$this->assertFalse(Validation::range('0x1', 1, 5), 'hex string data fails');
$this->assertFalse(Validation::range('\\x028', 1, 5), 'hexish encoding fails');
$this->assertFalse(Validation::range('0b010', 1, 5), 'binary string data fails');
$this->assertFalse(Validation::range('0x02', 1, 5), 'hex string data fails');
}
示例4: testInvalidRangeWithNonNumericValue
/**
* @testdox range should return false to non-numerical value
*/
public function testInvalidRangeWithNonNumericValue()
{
$value = 'Non numeric';
$this->assertFalse(Validation::range($value));
}
示例5: checkDateRange
/**
* checkDateRange
*
* @param array $question question
* @param string $answer answer value
* @return array error message
*/
public function checkDateRange($question, $answer)
{
$errors = array();
if ($question['is_range'] == QuestionnairesComponent::USES_USE) {
if (!Validation::range(strtotime($answer), strtotime($question['min']) - 1, strtotime($question['max']) + 1)) {
if ($question['question_type_option'] == QuestionnairesComponent::TYPE_OPTION_DATE) {
$fmt = 'Y-m-d';
} elseif ($question['question_type_option'] == QuestionnairesComponent::TYPE_OPTION_TIME) {
$fmt = 'H:i';
} else {
$fmt = 'Y-m-d H:i';
}
$errors[] = sprintf(__d('questionnaires', 'Please enter the answer between %s and %s.', date($fmt, strtotime($question['min'])), date($fmt, strtotime($question['max']))));
}
}
return $errors;
}
示例6: checkRangePassword
/**
* パスワードの確認
* 入力フォームと登録時のバリデーションの文字数が異なるため、独自実装する
*
* @param type $fields
* @return boolean
*/
function checkRangePassword($fields = array())
{
if (isset($this->data["TmpUser"]["id"])) {
return true;
} else {
return Validation::range(mb_strlen($this->data["TmpUser"]["password"]), 5, 21);
}
}
示例7: _validateTimeRange
/**
* _validateDatetime 日付・時間の正当性
*
* @param object &$model use model
* @param array $question 登録データに対応する項目
* @param string $answer 登録データ
* @return bool
*/
protected function _validateTimeRange(&$model, $question, $answer)
{
if ($question['is_range'] != RegistrationsComponent::USES_USE) {
return true;
}
$rangeResult = Validation::range(strtotime($answer), strtotime($question['min']) - 1, strtotime($question['max']) + 1);
if ($rangeResult) {
return true;
}
$model->validationErrors['answer_value'][] = sprintf(__d('registrations', 'Please enter the answer between %s and %s.'), date($this->_datetimeFormat[$question['question_type_option']], strtotime($question['min'])), date($this->_datetimeFormat[$question['question_type_option']], strtotime($question['max'])));
return false;
}