本文整理汇总了PHP中Validation::numeric方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::numeric方法的具体用法?PHP Validation::numeric怎么用?PHP Validation::numeric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validation
的用法示例。
在下文中一共展示了Validation::numeric方法的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: checkNumericType
/**
* checkNumericType
*
* @param array $question question
* @param string $answer answer value
* @return array error message
*/
public function checkNumericType($question, $answer)
{
$errors = array();
// 数値タイプの場合、数値型であるか
// 下限上限に引っかかってないか
if ($question['question_type_option'] == QuestionnairesComponent::TYPE_OPTION_NUMERIC) {
$chk = Validation::numeric($answer);
if (!$chk) {
$errors[] = __d('questionnaires', 'Number required');
}
}
return $errors;
}
示例3: testNumeric
/**
* testNumeric method
*
* @return void
*/
public function testNumeric()
{
$this->assertFalse(Validation::numeric('teststring'));
$this->assertFalse(Validation::numeric('1.1test'));
$this->assertFalse(Validation::numeric('2test'));
$this->assertTrue(Validation::numeric('2'));
$this->assertTrue(Validation::numeric(2));
$this->assertTrue(Validation::numeric(2.2));
$this->assertTrue(Validation::numeric('2.2'));
}
示例4: testInvalidNumeric
/**
* @testdox numeric should return false to invalid numbers
*/
public function testInvalidNumeric()
{
$value = '+-42.0asd53e25';
$this->assertFalse(Validation::numeric($value));
}
示例5: __checkMinMaxNumeric
/**
* __checkMinMaxNumeric
* min and max is require both value
*
* @param object &$model use model
* @param bool $check post data
* @return bool
*/
private function __checkMinMaxNumeric(&$model, $check)
{
if ($model->data['QuestionnaireQuestion']['question_type_option'] == QuestionnairesComponent::TYPE_OPTION_NUMERIC) {
if (!Validation::numeric($model->data['QuestionnaireQuestion']['min'])) {
return false;
}
if (!Validation::numeric($model->data['QuestionnaireQuestion']['max'])) {
return false;
}
}
return true;
}
示例6: assertId
/**
*
*
* @param integer|string $check
* @param string $type
* @return void
*/
public function assertId($check, $type = 'uuid')
{
switch ($type) {
case 'numeric':
$check = Validation::numeric($check);
break;
default:
$check = Validation::uuid($check);
$type = strtoupper($type);
}
if (!$check) {
parent::fail("Failed asserting that '{$check}' is a valid {$type} primary key.");
}
$this->addToAssertionCount(1);
}
示例7: formatNumeric
/**
* formatNumeric
* jpn: AdditionalValidationPatternsBehavior用にemptyのときはtrue
*
*/
public function formatNumeric(Model $model, $field)
{
$value = array_shift($field);
if (!Validation::notEmpty($value)) {
return true;
}
return Validation::numeric($value);
}