But IS_ALPHANUMERIC by virtue of its name suggests both letters and
numbers. Having separate validators for each of the cases would make
the code more readable.

db.auth_user.first_name.requires=IS_LETTERS()
db.auth_user.age.requires=IS_DIGITS()

is more readable and less ambiguous than

db.auth_user.first_name.requires=IS_ALPHANUMERIC(filter='letters')
db.auth_user.mobile.requires=IS_ALPHANUMERIC(filter='numbers')


On Aug 28, 10:13 pm, Bruno Rocha <[email protected]> wrote:
> Or maybe the IS_ALPHANUMERIC can be extended and receive aditional argument
> 'filter' to allow only letters or only numbers
>
> IS_ALPHANUMERIC(error_message='....', filter='numbers') # to allow only
> digits
> IS_ALPHANUMERIC(error_message='....', filter='letters')  # to allow letters
>
> can have some filter to allow special, underscores etc...
>
> http://web2py.com/book/default/docstring/IS_ALPHANUMERIC
>
>
>
>
>
>
>
>
>
> On Sun, Aug 28, 2011 at 1:54 PM, Saurabh Sawant <[email protected]> wrote:
> > Hi,
>
> > I think these validators would be a nice addition to the great set of
> > validators we already have. They can be useful for fields for names
> > and phone numbers.
>
> > class IS_LETTERS(Validator):
> >    """
> >    Checks if field's value consists of all letters
>
> >    example::
>
> >        INPUT(_type='text', _name='name', requires=IS_LETTERS())
>
> >        >>> IS_LETTERS()("A")
> >        ('A', None)
> >        >>> IS_LETTERS()("")
> >        ('', None)
> >        >>> IS_LETTERS()("A_")
> >        ('A_', 'enter only letters')
> >        >>> IS_LETTERS()("!")
> >        ('!', 'enter only letters')
> >    """
>
> >    def __init__(self, error_message='enter only letters'):
> >        IS_MATCH.__init__(self, '^[A-Za-z]*$', error_message)
>
> > class IS_DIGITS(Validator):
> >    """
> >    Checks if field's value consists of all numeric digits
>
> >    example::
>
> >        INPUT(_type='text', _name='name', requires=IS_DIGITS())
>
> >        >>> IS_NUMBERS()("1")
> >        ('1', None)
> >        >>> IS_NUMBERS()("")
> >        ('', None)
> >        >>> IS_NUMBERS()("A")
> >        ('A', 'enter only numbers')
> >        >>> IS_NUMBERS()("!")
> >        ('!', 'enter only numbers')
> >    """
>
> >    def __init__(self, error_message='enter only digits'):
> >        IS_MATCH.__init__(self, '^[0-9]*$', error_message)
>
> > Regards,
> > Saurabh Sawant
>
> --
>
> --
> Bruno Rocha
> [ About me:http://zerp.ly/rochacbruno]
> [ Aprenda a programar:http://CursoDePython.com.br]
> [ O seu aliado nos cuidados com os animais:http://AnimalSystem.com.br]
> [ Consultoria em desenvolvimento web:http://www.blouweb.com]

Reply via email to