Validate the answer with our Validator(s)

            This will support one or more validator classes being applied to
            this question.  If there are multiple, all validators must return
            True for the answer to be valid.
778600
def validate(self, answer):
        
        if answer is None:
            return False
        else:
            if isinstance(self.validator, list):
                for v in self.validator:
                    if not v.validate(answer):
                        return False
                return True
            else:
                return self.validator.validate(answer)
607967
public function validate($validator)
    {
        // Baily Early (if tags are used):
        
        if ($this->usesTags()) {
            return true;
        }
        
        // Call Parent Method (if not multiple):
        
        if (!$this->isMultiple()) {
            return parent::validate($validator);
        }
        
        // Obtain User Values:
        
        $values = $this->getValueArray();
        
        // Detect Invalid Values:
        
        $invalid = array_filter(
            $values,
            function ($userValue) {
                foreach ($this->getValidValues() as $formValue) {
                    if ($this->isSelectedValue($formValue, $userValue)) {
                        return false;
                    }
                }
                return true;
            }
        );
        
        // Answer Success (if none invalid):
        
        if (empty($invalid)) {
            return true;
        }
        
        // Define Validation Error:
        
        $validator->validationError(
            $this->getName(),
            _t(
                __CLASS__ . '.INVALIDOPTIONS',
                'Please select values within the list provided. Invalid option(s) {values} given.',
                [
                    'values' => implode(', ', $invalid)
                ]
            ),
            'validation'
        );
        
        // Answer Failure (invalid values detected):
        
        return false;
    }
808960
def valid?
      validations = properties_instances.collect do |property_type|
        if property_type.property.respond_to?(:valid?)
          property_type.property.valid?
        else
          true
        end
      end

      validations.all?
    end
381673
def validate(self, model, validator=None):
    
    for filter_ in self.filters:
      if not filter_(model):
        return True

    is_valid, message = self.is_valid(model, validator)
    if not is_valid:
      model.add_error(self.pretty_property_name or self.property_name, message)
    return is_valid
485086
def valid?(enumerator)
      return false unless Is[Enumerator].valid?(enumerator)

      enumerator.all? { |obj| Is[type].valid?(obj) }
    end
481755
def validate(self):
        
        super(BoolFilter, self).validate()

        self._value = truth(str(self._value), self._condition)
        self._condition = "yes" if self._value else "no"
93004
def validate(self, validators, resp_obj):
        
        self.validation_results = []
        if not validators:
            return

        logger.log_debug("start to validate.")

        validate_pass = True
        failures = []

        for validator in validators:
            # validator should be LazyFunction object
            if not isinstance(validator, parser.LazyFunction):
                raise exceptions.ValidationFailure(
                    "validator should be parsed first: {}".format(validators))

            # evaluate validator args with context variable mapping.
            validator_args = validator.get_args()
            check_item, expect_item = validator_args
            check_value = self.__eval_validator_check(
                check_item,
                resp_obj
            )
            expect_value = self.__eval_validator_expect(expect_item)
            validator.update_args([check_value, expect_value])

            comparator = validator.func_name
            validator_dict = {
                "comparator": comparator,
                "check": check_item,
                "check_value": check_value,
                "expect": expect_item,
                "expect_value": expect_value
            }
            validate_msg = "\nvalidate: {} {} {}({})".format(
                check_item,
                comparator,
                expect_value,
                type(expect_value).__name__
            )

            try:
                validator.to_value(self.test_variables_mapping)
                validator_dict["check_result"] = "pass"
                validate_msg += "\t==> pass"
                logger.log_debug(validate_msg)
            except (AssertionError, TypeError):
                validate_pass = False
                validator_dict["check_result"] = "fail"
                validate_msg += "\t==> fail"
                validate_msg += "\n{}({}) {} {}({})".format(
                    check_value,
                    type(check_value).__name__,
                    comparator,
                    expect_value,
                    type(expect_value).__name__
                )
                logger.log_error(validate_msg)
                failures.append(validate_msg)

            self.validation_results.append(validator_dict)

            # restore validator args, in case of running multiple times
            validator.update_args(validator_args)

        if not validate_pass:
            failures_string = "\n".join([failure for failure in failures])
            raise exceptions.ValidationFailure(failures_string)
1370108
def validate( self ):
        """"""
        klass = self.__class__

        for name in klass._fields:
            self.validate_field( name )
        return
69819
public boolean hasValidation() {
        if (validation) {
            return true;
        }
        if (CommonUtils.isNotEmpty(methods)) {
            for (MethodConfig methodConfig : methods.values()) {
                if (CommonUtils.isTrue(methodConfig.getValidation())) {
                    return true;
                }
            }
        }
        return false;
    }
553353
def handle_ans(self, ans_):
        
        ans = ans_.strip(' ')
        def chack_if_answer_was(valid_keys):
            return any([ans == key or ans.startswith(key + ' ')
                        for key in valid_keys])
        # Custom interactions
        for func, tup in self.actions.items():
            valid_keys = tup[0]
            if chack_if_answer_was(valid_keys):
                func()
797008
def validate_answer(self, value):
        
        # Check that the answer is JSON-serializable
        try:
            serialized = json.dumps(value)
        except (ValueError, TypeError):
            raise serializers.ValidationError("Answer value must be JSON-serializable")

        # Check the length of the serialized representation
        if len(serialized) > Submission.MAXSIZE:
            raise serializers.ValidationError("Maximum answer size exceeded.")

        return value
951573
public function validate($data, QuestionInterface $question, ScoreInterface $score)
    {
        $isValid = true;
        foreach ($question->getAnswers() as $answer) {
            if ($answer->isValid() && array_shift($data) != $answer->getId()) {
                $isValid = false;
                break;
            }
        }

        if (!$isValid) {
            $score->addNotValid();

            return false;
        }

        $score->addValid();

        return true;
    }
1085769
def valid?
      errors.clear

      validators.each do |validator|
        validator.validate(self)
      end

      errors.empty?
    end
3659
function() {
      var response = true;
      
      // Validate all the sub fields
      for (var i = 0 ; i < this.inputs.length ; i++) {
   	   var input = this.inputs[i];
   	   input.setClassFromState(); // update field classes (mark invalid fields...)
   	   var state = input.getState();
   	   if( state == inputEx.stateRequired || state == inputEx.stateInvalid ) {
   		   response = false; // but keep looping on fields to set classes
   	   }
      }
      return response;
   }
1277620
def answer(self):
        
        if isinstance(self.validator, list):
            return self.validator[0].choice()
        return self.validator.choice()
600508
def validate(self, value, model_instance, **kwargs):
        
        self.get_choices_form_class().validate(value, model_instance, **kwargs)
892126
def validate(self):
        
        try:
            assert self.kind == content_kinds.EXERCISE, "Assumption Failed: Node should be an exercise"

            # Check if questions are correct
            assert any(self.questions), "Assumption Failed: Exercise does not have a question"
            assert all(filter(lambda q: q.validate(), self.questions)), "Assumption Failed: Exercise has invalid question"
            assert self.extra_fields['mastery_model'] in MASTERY_MODELS, "Assumption Failed: Unrecognized mastery model {}".format(self.extra_fields['mastery_model'])
            return super(ExerciseNode, self).validate()
        except AssertionError as ae:
            raise InvalidNodeException("Invalid node ({}): {} - {}".format(ae.args[0], self.title, self.__dict__))