I want to restrict the string id to (a-z), (A-Z) and underscore. I replace underscores by 'a' before testing then run string.isalnum(). The function continues to work even when the user enters an id with non-alphanumerical value. This is the code:
def execute(id):
    test=id
    test=test.replace("_","a")
    if not test.isalnum:
        report("id is not valid, id must be (a-z,A-Z, _)")
        return
    #id is valid, continue working
    #the problem is that it continues working even if for example id ='location?#!!$%'
