By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

How to validate entry is alphanumeric,Tkinter

P: 3
I have an entry that i would like to make sure that it is only alphanumeric. how can i do so?
Expand|Select|Wrap|Line Numbers
  1. def validate_code(var):
  2.     new_value = var.get()
  3.     try:
  4.         new_value == '' or int(new_value)
  5.         validate_code.old_value = new_value
  6.     except:
  7.         var.set(validate_code.old_value)
  8.  
This is what I have so far. I already check if it is an int, now how to check if it is alphabet.
Thanks
Sep 28 '14 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 621
import string and test for new_value in string.letters
Try this simple test of your current logic
Expand|Select|Wrap|Line Numbers
  1. def validate_code(new_value):
  2.      ##new_value = var.get()
  3.      try:
  4.          new_value == '' or int(new_value)
  5.          validate_code.old_value = new_value
  6.      except:
  7.          print "error", validate_code.old_value
  8.  
  9. validate_code("@")
  10. validate_code(" ") 
Sep 28 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.