It should work. Can you show us more code and steps to reproduce the
problem?

On Nov 8, 5:14 am, villas <[email protected]> wrote:
> Hi Niphlod
>
> That's a good idea to test in the shell, where it worked fine.
>
> However, it still doesn't seem to work in the following contexts:
>
> Field('name','string', requires=CLEANUP() )
> --or--
> db.testtable.fieldstring.requires= CLEANUP()
>
> Maybe it's not meant to be used like that?
>
> Thanks for your help!
> -D
>
> On Nov 8, 1:42 am, Niphlod <[email protected]> wrote:
>
> > Hi, the method is correct, in the sense that CLEANUP() actually
> > removes leading and trailing space.
> > You should use .strip() only if you need to "preserve" special
> > characters in the field. Actually CLEANUP removes any special
> > character and newlines from the field (it applies the regex "[^ \n\w]"
> > and then remove all the matching items).
>
> > PS: It's easy to test out validators: just go to the shell and then:
> > - CLEANUP()('hello world!')
> > - CLEANUP()(' hi this is going to be stripped ')
> > - CLEANUP()('£uk3 $k1Walker')
>
> > and watch for the first element of the tuple (the second one contains
> > the errors usually but CLEANUP validator don't return them)
>
> > - ('hello world', None) #the ! has been removed
> > - ('hi this is going to be stripped', None) # leading and trailing
> > space removed
> > - ('uk3 k1Walker', None) # $ and £ removed
>
> > Niphlod
>
> > On 7 Nov, 21:25, villas <[email protected]> wrote:
>
> > > Hi All,
> > > I believe this is the correct way to remove leading and trailing
> > > spaces from strings.
>
> > > Q1.
> > > db.define_table('test',
> > >     Field('name','string', requires=CLEANUP() )
> > > )
> > > But I need regex in there? Sorry I couldn't figure the solution :(
>
> > > Q2.
> > > So, at the moment I am doing this instead:
> > >     if request.vars.name:
> > >         request.vars.name= request.vars.name.strip()
> > > Can anyone see a problem with this method? (Maybe it's better?).
>
> > > -D
>
>

Reply via email to