Everyone makes mistakes, so is not fair to say that "users are stupid" as an excuse when your application crashes due to user error. If you're a developer and your interface is so poorly designed that no one understands it and no error checking/handling is made, please don't blame the users (*). They probably just want to run that damn piece of software to execute some boring/complex task, and they don't want it to crash because they'll have to restart it over again ;-)

Regular expressions are very useful for checking errors in input text fields. Here you can find an example of how to validate an IP address or MAC address typed by the user. This is a pretty simple example, but you can use it as a base for whatever checking you need:


>>> pattern={\
... 'ip': re.compile(r"^(?:(?:25[0-5]\
... |2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25\
... [0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"),\
... 'mac': re.compile(r"^[0-9a-fA-F]{2}\:\
... [0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]\
... {2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}$")}
>>>
>>> # Is it a valid IP address?
... def valid_ip(address):
... if pattern['ip'].match(address) == None:
... return False
... return True
...
>>> valid_ip("192.168.0.1")
True
>>> valid_ip("192.168.0.457")
False
>>>
(*) If you truly believe that every user wants to mess with you... man, go to a shrink. I'm not kidding.