On 10/22/07, iain duncan <[EMAIL PROTECTED]> wrote:
>
> On Mon, 2007-22-10 at 11:36 -0500, Lukasz Szybalski wrote:
> > Hello,
> > I am trying to force a user to put in a 4 character year 1999,2004 etc
> > How do I do it in validators?
> >
> > This code below gives me a number and size of the field. Is there
> > another attribute that will force it to be 4 long?
> >
> > YEAR=widgets.TextField(validator=validators.Number(not_empty='True'),attrs={'size':4})
> >
> > Lucas
>
> Hi Lucas, you should look in the turbogears docs and formencode docs for
> how to make your own validator by subclassing Fancy Validator. It's not
> too hard, and once you've done it once, it's dead easy to do it the rest
> of time, allowing you to cusomize exactly how your constraints combine
> and what error messages you want to produce.
>
> The other option is to combine the above with the regular expression
> validator and pass in the re "\d{4}" or "\d\d\d\d". However, that won't
> let you as easily put in reasonable limits too. With a custom one you
> could make it accept and convert only a sensible range of years.
>
Actually I found an easier way.

YEAR=widgets.TextField(attrs={'size':4,'maxlength':4},validator=validators.All(validators.Number(not_empty='True'),validators.MinLength(4)))


Lucas
http://lucasmanual.com/mywiki/TurboGears#head-3674ae35bf3b32a5d3160c7fa6b3dddcba25232b

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to