This might be a silly question, but how would I get the length of a number using deform?
I have the following:
class BankingDetails(colander.MappingSchema):
""" Deform class to add an Agent's Banking Details """
account_number = colander.SchemaNode(
colander.Integer(),
validator=colander.Range(13),
missing=None,
widget=deform.widget.TextInputWidget(size=60))
bank_name = colander.SchemaNode(
colander.String(),
validator=colander.Length(max=100, min=3),
missing=unicode(''),
widget=deform.widget.TextInputWidget(size=60))
branch_code = colander.SchemaNode(
colander.Integer(),
validator=colander.Range(6),
missing=None,
widget=deform.widget.TextInputWidget(size=60))
I though that
validator=colander.Range(13),
would do it, but that only sets the minimum
value.
I thought range() would work as the python method returns a list congaing e.g. 13 entries. obviously I was wrong.
Is there a way for me to get the Integer's length using pyramid deform?
Use Range(max=10 ** 13)
(see the package documentation).
As mentioned by Sascha Gottfried below, you can use the min_err
and max_err
keyword arguments to set a custom error message.