Kun wrote:
> I have the following if statement that checks if a form is empty:
>
> if form.has_key("date") and form["date"].value != "":
> date=form['date'].value
>
> else:
> print "ERROR: No date entered!"
> raise Exception
>
> I would also like to add another
First, note that form["date"] is all you need. form["date"].value is
redundant.
I would do this with sets:
import string
if set(form["date"]) & set(string.ascii_letters) != set([]): print "You
have to enter a date with numbers"
if set(form["purchases"]) & set(string.digits) != set([]): print
"P
What about this?
import re
if not form.get('date'):
print "Tsk! No date entered."
raise Exception
if re.search('[a-zA-Z]', form.get('date')):
print "Tsk! No fancy date words."
raise Exception
date = form.get('date')
if not form.get('purchases'):
print "Ts
Something like this should work:
==
for c in form.get('date'):
if c in string.letters:
print "ERROR: You have to enter a date with numbers."
==
You have to import the string module. 'letters' is one of the
attributes defined in that module.
Other attributes