validate object, not form
764433
public function validate() {
    $errors = array();

    $enabled_servers = ldap_servers_get_servers(NULL, 'enabled');
    if ($this->ssoEnabled) {
      foreach ($this->sids as $sid => $discard) {
        if ($enabled_servers[$sid]->bind_method == LDAP_SERVERS_BIND_METHOD_USER || $enabled_servers[$sid]->bind_method == LDAP_SERVERS_BIND_METHOD_ANON_USER) {
          $methods = array(
            LDAP_SERVERS_BIND_METHOD_USER => 'Bind with Users Credentials',
            LDAP_SERVERS_BIND_METHOD_ANON_USER => 'Anonymous Bind for search, then Bind with Users Credentials',
          );
          $tokens = array(
            '!edit' => l($enabled_servers[$sid]->name, LDAP_SERVERS_INDEX_BASE_PATH . '/edit/' . $sid),
            '%sid' => $sid,
            '%bind_method' => $methods[$enabled_servers[$sid]->bind_method],
          );

          $errors['ssoEnabled'] = t('Single Sign On is not valid with the server !edit (id=%sid) because that server configuration uses %bind_method.  Since the user\'s credentials are never available to this module with single sign on enabled, there is no way for the ldap module to bind to the ldap server with credentials.', $tokens);
        }
      }
    }
    return $errors;
  }
1059004
def _validate(self, obj):
        
        report = ValidationReport()
        if not self.validator.is_valid(obj):
            for v in self.validator.iter_errors(obj):
                report.add_error("[%s] %s" % ('.'.join(str(vv) for vv in v.path), v.message))
        return report
514816
function isValid(date) {
  return Object.prototype.toString.call(date) == '[object Date]' && !isNaN(date.getTime());
}
242669
public function validateObject($object) {
        if (!$object instanceof SerialisableObject) {
            throw new ClassNotSerialisableException(get_class($object));
        }

        $classAnnotations = ClassAnnotationParser::instance()->parse($object);

        $validationFields = $classAnnotations->getFieldAnnotationsForMatchingTag("validation");

        $validationErrors = array();

        foreach ($validationFields as $field => $annotation) {

            $value = $object->__getSerialisablePropertyValue($field);

            foreach ($annotation[0]->getValues() as $validatorString) {

                $explodedValidator = explode("(", $validatorString);
                $validatorKey = trim($explodedValidator[0]);

                // Gather validator args if supplied.
                $validatorArgs = array();
                if (sizeof($explodedValidator) > 1) {
                    $argsCSV = explode(")", $explodedValidator[1]);
                    $args = explode("|", $argsCSV[0]);

                    foreach ($args as $arg) {
                        $validatorArgs[] = trim($arg);
                    }
                }

                $validator = isset($this->validators[$validatorKey]) ? $this->validators[$validatorKey] : null;
                if (isset($validator)) {
                    $valid = $validator->validateObjectFieldValue($value, $field, $object, $validatorArgs, $validatorKey);

                    if ($valid !== true) {
                        if (!isset($validationErrors[$field])) $validationErrors[$field] = array();
                        $message = preg_replace_callback("/\\$([0-9])/", function ($matches) use ($validatorArgs) {
                            return $validatorArgs[$matches[1] - 1];
                        }, $validator->getValidationMessage());
                        $validationErrors[$field][$validatorKey] = new FieldValidationError($field, $validatorKey, $message);
                    }

                } else {
                    throw new InvalidValidatorException($validatorKey, $field, $object);
                }


            }

        }

        return $validationErrors;


    }
936942
function() {
    // Check for unknown attributes
    var key, unknownAttrs = []
    for (key in obj) {
      if (!self.validators.hasOwnProperty(key))
        unknownAttrs.push(key)
    }
    if (unknownAttrs.length)
      self._merge(validationErrors, 'unknown attributes [' + unknownAttrs.join(', ') + ']', prefix)
      //validationErrors[prefix || '.'] = 'unknown attributes [' + unknownAttrs.join(', ') + ']'

    // Run the `after` hook only if there is no validation error.
    if (isValid && self.after) {
      try {
        self.after.call(obj)
      } catch (err) {
        if(!_handleError(err)) return done(err)
      }
    }
    done(null, validationErrors)
  }
790044
def form_valid(self, form):
        """"""
        instance = form.save(commit=False)
        if hasattr(self.request, 'user'):
            instance.user = self.request.user
        if settings.CONTACT_FORM_FILTER_MESSAGE:
            instance.message = bleach.clean(
                instance.message,
                tags=settings.CONTACT_FORM_ALLOWED_MESSAGE_TAGS,
                strip=settings.CONTACT_FORM_STRIP_MESSAGE
            )
        instance.ip = get_user_ip(self.request)
        instance.site = self.site
        instance.save()
        if settings.CONTACT_FORM_USE_SIGNALS:
            contact_form_valid.send(
                sender=self,
                event=self.valid_event,
                ip=instance.ip,
                site=self.site,
                sender_name=instance.sender_name,
                sender_email=instance.sender_email,
                email=instance.subject.department.email,
                subject=instance.subject.title,
                message=instance.message
            )

        return super(ContactFormView, self).form_valid(form)
576005
def validate(self, obj, **kwargs):
        """"""
        text = stringify(obj)
        if text is None:
            return False
        if '.' not in text:
            return False
        if '@' in text or ':' in text:
            return False
        if len(text) < 4:
            return False
        return True
486443
function validateInputAsJson() {
  if (this.value) {
    try {
      JSON.parse(this.value);
      setValidationClasses(this, true);
    }
    catch(e) {
      setValidationClasses(this, false);
    }
  }
  else {
    setValidationClasses(this, false)
  }
}
801442
private void validate(Object object) {
		Set<ConstraintViolation<Object>> viols = validator.validate(object);
		for (ConstraintViolation<Object> constraintViolation : viols) {
			if (Null.class.isAssignableFrom(constraintViolation.getConstraintDescriptor().getAnnotation().getClass())) {
				Object o = constraintViolation.getLeafBean();
				Iterator<Node> iterator = constraintViolation.getPropertyPath().iterator();
				String propertyName = null;
				while (iterator.hasNext()) {
					propertyName = iterator.next().getName();
				}
				if (propertyName != null) {
					try {
						PropertyDescriptor descriptor = BeanUtils.getPropertyDescriptor(o.getClass(), propertyName);
						descriptor.getWriteMethod().invoke(o, new Object[] { null });
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
84777
function ( obj ) {
		return obj.nodeName === "FORM" ? validate.test( obj ) : !string.isEmpty( obj.value || element.text( obj ) );
	}
206244
def _validated(self, data):
        """"""
        errors = []
        for sub in self.schemas:
            try:
                return sub(data)
            except NotValid as ex:
                errors.extend(ex.args)

        raise NotValid(' and '.join(errors))
1160437
function ( obj ) {
		return obj.nodeName === "FORM" ? false : string.isEmpty( obj.value || element.text( obj ) );
	}
967622
def get_validated_object(self, value):
        
        try:
            if self.get_field_type().check_value(value) or self.get_field_type().can_use_value(value):
                data = self.get_field_type().use_value(value)
                self._prepare_child(data)
                return data
            else:
                return None
        except AttributeError:
            return value
1302754
def validate_object(obj, field_validators=None, non_field_validators=None,
                    schema=None, context=None):
    
    if schema is None:
        schema = {}
    if context is None:
        context = {}
    if field_validators is None:
        field_validators = ValidationDict()
    if non_field_validators is None:
        non_field_validators = ValidationList()

    from flex.validation.schema import (
        construct_schema_validators,
    )
    schema_validators = construct_schema_validators(schema, context)
    if '$ref' in schema_validators and hasattr(schema_validators['$ref'], 'validators'):
        ref_ = field_validators.pop('$ref')
        for k, v in ref_.validators.items():
            if k not in schema_validators:
                schema_validators.add_validator(k, v)

    if 'discriminator' in schema:
        schema_validators = add_polymorphism_requirements(obj, schema, context, schema_validators)
        # delete resolved discriminator to avoid infinite recursion
        del schema['discriminator']

    schema_validators.update(field_validators)
    schema_validators.validate_object(obj, context=context)
    non_field_validators.validate_object(obj, context=context)
    return obj
441339
def validate(self, obj_to_validate, is_substitute=True):
        
        res = []
        for check in self.__cfg[Validator.__CFG_KEY_CHECKS]:
            self.__logger.info('Performing {} validation against {}'.format(check, obj_to_validate))
            check_res = Check(self.__cfg[Validator.__CFG_KEY_CHECKS][check]).validate(obj_to_validate, is_substitute)
            if check_res:
                if type(check_res) == dict:
                    res.append(check_res)
                else:
                    res.extend(check_res)
        return None if len(res) == 0 else res
635708
function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
    {
        /// Get object for input validation
        // To do: only validate, not save data
        $xmlText = $this->objectAttributeContent( $contentObjectAttribute );
        $input = $xmlText->attribute( 'input' );
        $isValid = $input->validateInput( $http, $base, $contentObjectAttribute );

        return $isValid;
    }
391923
def ensure_object_is_string(item, title):
    
    assert isinstance(title, str)

    if not isinstance(item, str):
        msg = "{} must be a string. {} passed instead."
        raise TypeError(msg.format(title, type(item)))

    return None