How to validate entry is alphanumeric,Tkinter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • katyalrikin
    New Member
    • Sep 2014
    • 3

    How to validate entry is alphanumeric,Tkinter

    I have an entry that i would like to make sure that it is only alphanumeric. how can i do so?
    Code:
    def validate_code(var):
        new_value = var.get()
        try:
            new_value == '' or int(new_value)
            validate_code.old_value = new_value
        except:
            var.set(validate_code.old_value)
    This is what I have so far. I already check if it is an int, now how to check if it is alphabet.
    Thanks
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    import string and test for new_value in string.letters
    Try this simple test of your current logic
    Code:
    def validate_code(new_value):
         ##new_value = var.get()
         try:
             new_value == '' or int(new_value)
             validate_code.old_value = new_value
         except:
             print "error", validate_code.old_value
    
    validate_code("@")
    validate_code(" ")

    Comment

    Working...