title: How to find all the special characters in a user-given string in Python?
body: <p>I am building a GUI BMI Calculator app using Python and tkinter and I need some help.</p>
  
  <p>Since there must be no special characters in the user given string, I want an efficient way to detect special characters in a string.</p>
  
  <p>I used regex compile method as I saw online. But it did not detect all the special characters. As when I gave 165,56 instead for 165.56, it returned and error in console. Other characters like #$@!$ etc, all worked perfectly showing tkMessageBox as I programmed.</p>
  
  <p>I've tried each character in string iterating through and finding if special characters are present and I even used regex compile as mentioned above but none satisfies my queries.</p>
  
  <pre><code>    regex = re.compile('[@_!#$%^&amp;*()&lt;&gt;?/\|}{~:]')
  
  #assume have already got the value for h from user as 165,65
      h = Entry.get(heightEntry)
      if not h:
          h = "0"
          height = 0
      elif h.isdigit() == True:
          height = float(h)
      elif h.isalnum() == True:
          height = "None"
      elif regex.search(h) == None:
          for x in h:
              if "." in x:
                  y += 1
          if y &gt;=2:
              height = "None"
          else:
              height = float(h)
      else:
          height = "None"
  
  #Check height lies between 0.5m and 3.0m or 50cm to 300cm
      if not height:
          print("There is no value for height to calculate")
          tkMessageBox.showerror("Alert","No height value")
      else:
          if height == "None":
              print("Invalid height value")
              tkMessageBox.showerror("Alert","Invalid height value")
              height = 0
          elif not ((50.0&lt;=height&lt;=300.0) or (0.5&lt;=height&lt;=3.0)):
              print("Invalid height value",height)
              tkMessageBox.showerror("Alert","Invalid height value")
          else:
              if 50.0&lt;=height&lt;=300.0:
                  print("Height:",height,"cm")
              else:
                  print("Height:",height,"m")
  </code></pre>
  
  <p>I expected the outcome to show the message box below height == "None"</p>
  
  <p>But it showing traceback most recent call error.</p>