code: def validate(self):
          
          # Don't call the validator again, if it was already called for the
          # current input.
          if self.validation_state != ValidationState.UNKNOWN:
              return self.validation_state == ValidationState.VALID
  
          # Validate first. If not valid, set validation exception.
          if self.validator:
              try:
                  self.validator.validate(self.document)
              except ValidationError as e:
                  # Set cursor position (don't allow invalid values.)
                  cursor_position = e.cursor_position
                  self.cursor_position = min(max(0, cursor_position), len(self.text))
  
                  self.validation_state = ValidationState.INVALID
                  self.validation_error = e
                  return False
  
          self.validation_state = ValidationState.VALID
          self.validation_error = None
          return True
docs: Returns `True` if valid.