def dbref(dbref, reqhash=True):
    if reqhash:
        num = (int(dbref.lstrip('#')) if (isinstance(dbref, basestring) and
                                           dbref.startswith("#") and
                                           dbref.lstrip('#').isdigit())
                                       else None)
        return num if num > 0 else None
    elif isinstance(dbref, basestring):
        dbref = dbref.lstrip('#')
        return int(dbref) if dbref.isdigit() and int(dbref) > 0 else None
    else:
        return dbref if isinstance(dbref, int) else None
Converts/checks if input is a valid dbref.
dataset/ETHPy150Open evennia/evennia/evennia/utils/utils.py/dbref