Hi all,
What's the recommended way to restrict input? For instance, I store a
phone number as an integer, and I need it to have 7, 10, or 11 digits.
In its getter, I format it so it looks good as a string, and in its
setter, I take the string the user inputs, strip only the integers,
and store those.

To inforce my length restriction, I have it set up something like this:

class Customer(base):
 _phone = Column("phone", Integer)

 @property
 def phone(self):
  #return pretty string

 @phone.setter
 def phone(self, value):
  #intsInPhone is a list of the integers in "value"
  if len(intsInPhone) not in [7, 10, 11]: #invalid length
   raise ValueError, "Phone numbers must be 7, 10, or 11 digits"

Is there a way I should do this instead? I had to make properties
anyway, since user-inputted values are coming from a dialog and will
always be strings--I had to convert them to the proper types, and
output formatted strings in some cases. I figured this was a good
place for a little validation while I was at it.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to