from gluon.validators import Validator class CLEANUP_JUST_NUMBERS(Validator): '''Filters a field stripping out non-numeric chars from it. ''' def __call__(self, value): chars = [c for c in value if c.isdigit()] return (''.join(chars), None)
If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!
from gluon.validators import Validator class CLEANUP_JUST_NUMBERS(Validator): '''Filters a field stripping out non-numeric chars from it. ''' def __call__(self, value): chars = [c for c in value if c.isdigit()] return (''.join(chars), None)
Comments (1)
0
rochacbruno 11 years ago
Is it really needed to have the __init__ method? I did not tested, but, the init is doing nothing.
requires=CLEANUP_JUST_NUMBERS() will create an object without the need to pass any argument.
Also I never created a subclass of Validator. I always use just "object" and it works. There is some advantage on subclassing Validator?
BTW: Thanks for the slice!
replies (1)