'Return True if string is valid'

def is_valid(self, qstr=None):

    if (not self.help.source_is_console()):
        return True
    if (qstr is None):
        qstr = self.currentText()
    if (not re.search('^[a-zA-Z0-9_\\.]*$', str(qstr), 0)):
        return False
    objtxt = to_text_string(qstr)
    if self.help.get_option('automatic_import'):
        shell = self.help.internal_shell
        if (shell is not None):
            return shell.is_defined(objtxt, force_import=True)
    shell = self.help.get_shell()
    if (shell is not None):
        try:
            return shell.is_defined(objtxt)
        except socket.error:
            shell = self.help.get_shell()
            try:
                return shell.is_defined(objtxt)
            except socket.error:
                pass
