[Zope] way to cleanup form input text?
sean.upton@uniontrib.com
sean.upton@uniontrib.com
Fri, 12 Jan 2001 09:06:17 -0800
Write an external method in python that uses regsub.sub or regsub.gsub
functions. This allows you to do regular expression substitutions.
regsub.sub does a replace on the first match only
regsub.gsub does a replace on all matches
Ex:
import regsub
def process_a_string(self):
"""Processes a string, where string is passed as self"""
result=regsub.gsub('[ \t][ \t]+', ' ', self) #Filters all
duplicate spaces and
return result #tabs down
to one space char
where somestring is our example attribute call this in dtml:
<dtml-var expr="process_a_string(somestring)">
is somemethod is a method returning a string:
<dtml-var expr="process_a_string(somemethod())">
Sean
-----Original Message-----
From: Chris Beaumont [mailto:cbeaumon@msri.org]
Sent: Thursday, January 11, 2001 3:43 PM
To: zope@zope.org
Subject: [Zope] way to cleanup form input text?
Is there a simple way to clean up text that's input to HTML forms in Zope?
I have a situation where one of my users is copying text from her web
browser and pasting it into Zope.
I'm sure this is a common problem..
The input text ends up having runs of whitespace characters in it
that I'd like to prune down to one each..and I think it's also been
the source of some non-standard, unwanted characters that cause
problems if they end up getting into our database..
I'm sure someone else has encountered this problem before..what's the
best way to fix it? The string module doesn't seem to have what I
want.. (or at least I couldn't find it..) The worst problems seems
to be long strings of spaces or tabs that I'd like to turn into
single spaces..(each)
Thanks!
Chris
cbeaumon@msri.org
_______________________________________________
Zope maillist - Zope@zope.org
http://lists.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://lists.zope.org/mailman/listinfo/zope-announce
http://lists.zope.org/mailman/listinfo/zope-dev )